• Post Reply Bookmark Topic Watch Topic
  • New Topic

How many times threads wake up from sleep before going dead?  RSS feed

 
subodh gupta
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So i have task which runs after every 1 hour. I know there specialized libs which can perform this job better but i want to know why can't thread sleeping for an hour can't complete this task?
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your not too concerned about losing a few seconds here and there a Thread sleeping for an hour could work. What makes you think it will not work?
 
subodh gupta
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because its not working. It runs fine for few weeks/months but than thread makes the normal exit without any exception.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16059
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's probably a bug in your code. Can you post the code, so that we can have a look at it?
 
subodh gupta
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
code is like this:

1. while loop (flagged false on application context down)
2. perform task
3. try block
4. thread sleep for 1 hr
5. catch throwable
6. log exception
7. while ends

message on method exit

So only two things can happen here either application context has been reset (using tomcat 6 as app server) or thread has died without any exception.
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
flagged false on application context down


don't understand what your checking here?
 
subodh gupta
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have implemented the ServletContextListener interface and on call of contextDestroyed i set a flag false which terminates the thread.

Oh can this be a problem in a single instance machine where no load balancer is configured.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!