Hello, my name is Sandra. I have a question about wait() and notify() in Java.
The task is to implement something like:
1) wait for the boolean variable "world" to be true
2) when its true, then run "usa()"
Write a method by extending the existing class...
the starting point is:
class abc { private bool world; public static usa(){System.out.println("USA");} }
Now i have to implement the task using wait() and notify/notifyAll().
My solution is:
class abc { private bool world; public static usa(){System.out.println("USA");} public synchronized void act(){ while (!world) try{ wait(); } catch(InterruptedException ex) usa(); notifyAll();} }
Is this correct? Sorry, i have no java skills, but we have to take this course
So pls help me