In the above pgm (for all my pgm inmy JVM), first everything in the main thread is executing and then only new thread is executed and I am also aware of Thread Scheduler is not guaranteed..
What my question is in the main thread itself notifyall/notify will be executed. without wait is executed in the new thread, which causes the pgm not to terminate..right? In the above pgm, notifyall() will be executed first, then wait() is executing, but nothing to notify() the wait(), since notifyall() is executed already..and as i expected this causes pgm not to be terminated, but it prints some number..how it is possible?can anyone explain this?
SCJP 1.4 (86%), SCWCD 1.4 (86%), SCBCD 1.3 (85%), SCDJWS (Just Started...) - Satisfaction Lies in Our EFFORT, Not in the ATTAINMENT
posted 9 years ago
i'm afraid of a compilation error.
inside the for loop, can you declare A t1 = new A(this)? that means t1 gets repeatly declared following the loop progress.
when move the declaration out of the for loop, i except the call flow as following,
main thread: new B().m1(); main thread: t1.start(); t1 threads 0-9: this.wait(); main thread: System.out.println("1"); main thread: this.notifyAll(); t1 threads 0-9: System.out.print(Thread.currentThread().getName());