Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Thread.sleep

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ???
 
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
author
Posts: 23877
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Run away! Run away! Here, take this tiny ad with you:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic