In which object should I implement wait()/notify()?

Posted by Christopher Francisco on Programmers See other posts from Programmers or by Christopher Francisco
Published on 2014-06-07T13:32:20Z Indexed on 2014/06/07 15:38 UTC
Read the original article Hit count: 277

I'm working in an Android project with multithreading. Basically I have to wait to the server to respond before sending more data.

The data sending task is delimited by the flag boolean hasServerResponded so the Thread will loop infinitely without doing anything until the flag becomes true.

Since this boolean isn't declared as volatile (yet), and also looping without doing anything wastes resources, I thought maybe I should use AtomicBoolean and also implement wait() / notify() mechanism.

Should I use the AtomicBoolean object notify() and wait() methods or should I create a lock Object?

© Programmers or respective owner

Related posts about java

Related posts about object-oriented