File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA 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: 18765
    
  40

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)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Thread for a given time window