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 SET TIME OUT with TIMER Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "SET TIME OUT with TIMER" Watch "SET TIME OUT with TIMER" New topic
Author

SET TIME OUT with TIMER

Zaafir Barahim
Ranch Hand

Joined: Dec 12, 2006
Posts: 36
can i please get an example, codes to enable setTimeout in a timer. Thanks in advance. Its vvvv urgent. Please help me
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18834
    
  40

Originally posted by Zaafir Barahim:
can i please get an example, codes to enable setTimeout in a timer. Thanks in advance. Its vvvv urgent. Please help me


Neither the java.util.Timer or the javax.swing.Timer class has a timeout feature. Hence, no setTimeout() method, and no enable of that feature.


Now... By timeout I am assuming that you mean some sort of results return when the task is not completed within a certain amount of time. Unfortunately, you will have to implement this yourself.

Have your long running task periodically check a certain flag, say some sort of abort flag. If the abort flag is set, then it will have to exit cleanly. You will then need another timer task which will set this abort flag, and report that the timeout occurred.

And BTW, this timeout task can't use the same java.util.Timer -- so create another one. You shouldn't be executing long running tasks in a javax.swing.Timer, so I will assume you mean java.util.Timer.

Henry
[ February 19, 2007: Message edited by: Henry Wong ]

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SET TIME OUT with TIMER