• 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

wait() method

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the use of having timeout argument for the wait() method?
If i understand correctly, both when the
(1)thread is notifiied and when the
(2)time in the wait method expires,
the thread goes to Blocked-for-lock acquisition state.And when the lock on the object is released it goes to ready-to-run state and then to running state whenever it gets chance.

So the call to wait() method returns at the same time in both cases.

And also when the thread is interrupted, does the thread go to Blocked-for-lock acquisition state-->>Ready State-->>Running annd then throws the InterruptedException.Please correct me if i am wrong.
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you specify wait time in milli seconds then the thread will stop waiting after that time. You could say wait(1000) and make the thread to wait for 1 second and then continue execution or if the thread is notified or interrupted before 1second execution of the rest of the program will continue
 
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


And also when the thread is interrupted, does the thread go to Blocked-for-lock acquisition state-->>Ready State-->>Running annd then throws the InterruptedException.Please correct me if i am wrong.



When the thread is interrupted by another thread, an InterruptedException is thrown AFTER the thread regains it's lock on the object
 
reply
    Bookmark Topic Watch Topic
  • New Topic