aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread.sleep Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread.sleep" Watch "Thread.sleep" New topic
Author

Thread.sleep

Rishi Chopra
Ranch Hand

Joined: Mar 07, 2004
Posts: 108
I have a class 'BaseClass' that extends a java.lang.Thread but does not implement run() method. but it defines some common methods

SubClass
Now i have a subclass 'SubClass' that extends 'BaseClass' and provides a run() method implementation. In the main method in this class, start method is called is on object of the baseclass. In the run method, some process is done and then thread is made to sleep for 10 seconds. After wakeup,it should redo the process (calling a stored proc )

SubClass2
There is another subclass 'SubClass2' that extends 'BaseClass' and provides a run() method implementation. In the main method in this class, start method is called is on object of the baseclass. In the run method, some process is done and then thread is made to sleep for 10 seconds. After wakeup,it should redo the process (calling a stored proc )

Now these two subclasses are run as a unix process , but the problem is these processes dies off automatically..


HOW ???


Life is Beautiful Learn to See it.........
Santhosh Kumar
Ranch Hand

Joined: Nov 07, 2000
Posts: 242
If you post the code snippets, makes it easier to clearly answer you question.

I believe (from your post) that you are creating objects like new BaseClass(), in SubClass.main and SubClass2.main methods. In this case, Thread object would execute its own run() method (which is empty implementation) as it cannot see the SubClass.run and SubClass2.run methods. That's the reason the threads are dieing immediately.

Changin new BaseClass(), to new SubClass() or new SubClass2() would fix the problem and Thread object would be able to run the respective run methods.
Rishi Chopra
Ranch Hand

Joined: Mar 07, 2004
Posts: 108
i am creating new SubClass() and new SubClass2() in the main only and not new BaseClass(), then also after sometime the processes dies off i.e it does not come out of sleep mode
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18990
    
  40

Can we have some code that shows what you are describing? the phrase "sometime the processes dies off i.e it does not come out of sleep mode" doesn't describe it very well.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
 
subject: Thread.sleep