This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes notify thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "notify thread" Watch "notify thread" New topic

notify thread

jagat thoudam

Joined: Jul 20, 2009
Posts: 1
class TestThread extends Thread{
public void restart(){
public static void startMe(){
System.out.println("Trying to Notify");

public void run()

catch(InterruptedException e){}

public static void main(String[] args){
TestThread t1 = new TestThread();



Why is the thread not notified?
shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
since you are calling wait() on instance object, to get your thread notified you have to call notify on the instance object. Problem with your code is you are calling notifyAll() on the class object.

change your code as followes :

SCJP 1.5(97%) My Blog
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 43396
Welcome to JavaRanch

I am not convinced that wait and notify are beginners' topics, so I shall move this thread.
shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
startMe() is getting executed prior to run(). put main thread to sleep for some time, to make sure run() is executed prior to startMe().

I agree. Here's the link:
subject: notify thread
It's not a secret anymore!