If so, is it safe to do this way?
public class ThTest implements Runnable
{
public static void main(String[] args) throws Exception
{
new ThTest().runThis();
}
public void runThis()
{
Thread m1 = new Thread(this);
Thread m2 = new Thread(this);
Thread m3 = new Thread(this);
m1.start();
m2.start();
m3.start();
}
public void run()
{
System.out.println("It's me
");
notify();
}
public void myFun() throws Exception
{
wait();
}
}
I get the following when I run this:
It's me
java.lang.IllegalMonitorStateException: current thread not owner
at java.lang.Object.notify(Native Method)
at ThTest.run(ThTest.java:25)
at java.lang.Thread.run(Thread.java:479)
It's me
java.lang.IllegalMonitorStateException: current thread not owner
at java.lang.Object.notify(Native Method)
at ThTest.run(ThTest.java:25)
at java.lang.Thread.run(Thread.java:479)
It's me
java.lang.IllegalMonitorStateException: current thread not owner
at java.lang.Object.notify(Native Method)
at ThTest.run(ThTest.java:25)
at java.lang.Thread.run(Thread.java:479)