File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes problem with wait,notify Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "problem with wait,notify" Watch "problem with wait,notify" New topic
Author

problem with wait,notify

maggie karve
Ranch Hand

Joined: Dec 29, 2009
Posts: 186
when i compile this i just get thread waiting but not getting notified.....
but when i compile other codehere my thread gets notified???why cant previous thread get notified???how to get it notified???
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
try this code:


SCJP 1.6 96%
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
problem in your code is you are not starting any new thread whole program is running under one single main thread so when you call show method it puts the thread to wait and the code that notifies the thread is never reached.
but in the second code you used overloaded version of wait which comes to runnable after the time specified no matter it is notified or not.
maggie karve
Ranch Hand

Joined: Dec 29, 2009
Posts: 186
thanks ......when i tried this after sometime i got correct answer......
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

I find your code highly unreadable and confusing. It took me a couple of times reading it before I got it. It's generally discouraged to extend the thread class. Why not use Runnables? I think this code is better readable:



"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Manish Awasthy
Greenhorn

Joined: Jan 11, 2010
Posts: 25
@ Wouter nice quote man
"Any fool can write code that a computer can understand.
Good programmers write code that humans can understand."
--- Martin Fowler


SCJP 1.6 98%

"Successful People Don't Plan Results,They Just Plan Proper Beginings.Right Result Always Follow Right Begining".
 
Don't get me started about those stupid light bulbs.
 
subject: problem with wait,notify
 
Similar Threads
book K&B self test q16........problem
what all ways a Thread can leave a lock on Object
On threads
wait and notify
Removing entry from HashMap when storing ReentrantLocks safely