aspose file tools*
The moose likes Threads and Synchronization and the fly likes Thread for a given time window Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Thread for a given time window" Watch "Thread for a given time window" New topic
Author

Thread for a given time window

hansi flick
Greenhorn

Joined: Nov 09, 2010
Posts: 1
I'd like to run a Listener in a Thread from a certain point of time on for a certain amount of time (some hours).
I found Timer and TimerTask classes, however JavaDoc tells me that TimerTasks should complete quickly, which is not the case for my Thread. Is there a better and easy possibility to achieve the task?
Thanks
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18103
    
  39

hansi flick wrote:I found Timer and TimerTask classes, however JavaDoc tells me that TimerTasks should complete quickly, which is not the case for my Thread. Is there a better and easy possibility to achieve the task?
Thanks


TimerTasks should complete quickly because there is only one thread that is dedicated to the tasks -- having a long running task can starve the other tasks.

If you only have a single task in the timer, then it shouldn't be a problem.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Thread for a given time window
 
Similar Threads
Simple question about threads
Regarding Thread pool stuck and servers getting overloaded
Passed with 152/155 (98%)
Sending Scheduled Emails
How to block the execution of Thread