• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Couple of Thread Qs from JQPlus

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers.
These are just some snippets from a couple of JQ+ thread Qs.
Q1) When a thread calls notify() from within its synchronized block, does it say to the waiting threads that "Hey! Guys, I am relinquishing the lock on this object." & actually does so ?
Q2) Can a join operation on a thread cause some other thread to stop?
Thanks
- Himanshu
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A1) No. Unlike wait(), which blocks immediately and gives up its lock, notify() and notifyAll() won't actually give up the lock on the object until execution exits the synchronized block in which the notify()/notifyAll() is located.
Example:
...
synchronized(this){
//do stuff
notify(); //thread not block, nor locks surrendered
//do more stuff
} //end of synchronized block, thread gives up locks

A2) Yes. Calling join() on thread A causes the current thread to be suspended until thread A completes, at which time the thread that invoked join() will continue.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
there are other version of the join(), which waits for milli seconds, for a thread to complete, then starts whether or not calling thread has got its execution complete or not.
 
If a regular clown is funny, then a larger clown would be funnier. Math. Verified by this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic