• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Order of execution for wait and notify/notifyall

 
Ranch Hand
Posts: 344
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From web page


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?
 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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());
 
I've never won anything before. Not even a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic