aspose file tools
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 OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP 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: 40449
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().

wood burning stoves
subject: notify thread