JAVA synchronize multiple methods with notify/wait

so i have multiple threads calling 2 methods setNext and makeTurn. I have to ensure that only 1 thread can call setNext(which calls makeTurn by a super call from the parent class) and waits for finished execution of makeTurn before the next thread can enter setNext.

@Override

public void setNext(Player nextPlayer) {

super.nextPlayer(nextPlayer);

//this method isn´t thread safe,calls makeTurn after initialising

}

@Override

public void makeTurn() {

super.makeTurn();

//not thread safe call from parent class

}

So my idea was to use synchronized keyword on methods. The problem is that only thread 1 is executing-> sets next to thread 2 and...

Read More »

By: StackOverFlow - Sunday, 17 June

Related Posts