class BCell { // can result in deadlocks int value; public synchronized int getValue() { return value; } public synchronized void setValue(int i) { value = i; } public synchronized void swap(BCell x) { int temp = getValue(); setValue(x.getValue()); x.setValue(temp); } }