What happens after Wait synchronization?

Asked

Viewed 52 times

2

Look at these two codes in separate threads

Thread A

synchronized(objeto) {
    while(condicao)
        objeto.wait();
    //operações
}

Thread B

synchronized(objeto) {
    condicao = false;
    objeto.notify();
    //operações
}

Operations will be subject to block synchronization ?

  • 2

    Yes, operations will be subject to block synchronization.

1 answer

1


Yes, since objeto == objeto.

A common problem, especially in complex systems, is that at some point you end up having duplicate instances of objects that should be Singleton or, on the contrary, share instances that should not be shared.

Another common multi-threading problem is not properly controlling outages and timeouts. Not treating these things can cause the program to end unexpectedly or to remain eternally blocked, for example.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.