Saved Bookmarks
| 1. |
What is the best possible way to call the wait() method - by using the if construct or the loop construct? |
|
Answer» wait() should be called in loop construct always because whenever a thread gets resources to execute again, it is always better to check the condition before execution. The standard way of wait and notify usage is as shown below: synchronized (resource) {while (wait condition) resource.wait(); // release the resource lock and reacquire it post wait // operations to perform } |
|