• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread.sleep

 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Would you like to try a free sample? Today we are featuring tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic