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 How to run  Multiple Timer  Tasks concurrently?? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "How to run  Multiple Timer  Tasks concurrently??" Watch "How to run  Multiple Timer  Tasks concurrently??" New topic
Author

How to run Multiple Timer Tasks concurrently??

Rohan Kayan
Ranch Hand

Joined: Sep 17, 2004
Posts: 123
I am creating multiple timerTasks and scheduling them with one timer for immediate start . Now I am confused that are they running concurrently or in sequential basic with the repetition interval of 10 seconds , what will happen if one task goes in unending loop . Will other tasks execute or not ???

Please help me out..............


SCWCD 1.4, SCJP 1.4
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Can you try it, and inform us?


http://home.arcor.de/hirnstrom/bewerbung
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16695
    
  19

The standard java.util.Timer class only creates one thread, hence, long lived tasks will affect other tasks to be executed.

With Java 1.5, there is the ScheduledThreadPoolExecutor class, that allows you specify the number of threads.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
You could make your tasks spawn new threads, too. That way they'd end almost instantly as far as the Timer thread can tell. If you have lots threads being set up and torn down, the JDK 5 thread pooling stuff might be a good idea.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Rohan Kayan
Ranch Hand

Joined: Sep 17, 2004
Posts: 123
Originally posted by Henry Wong:
The standard java.util.Timer class only creates one thread, hence, long lived tasks will affect other tasks to be executed.

With Java 1.5, there is the ScheduledThreadPoolExecutor class, that allows you specify the number of threads.

Henry



Thanks Henry for your reply , What will happen if I am going to use multiple Timer instance , Shall it start working concurrently or not ??
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16695
    
  19

Originally posted by Rohan Kayan:
Thanks Henry for your reply , What will happen if I am going to use multiple Timer instance , Shall it start working concurrently or not ??


Each Timer instance will start another thread -- so yes, you will achieve concurrency. However, if it is a repeating task, then long running tasks may still affect the next iteration of the task.

Henry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to run Multiple Timer Tasks concurrently??
 
Similar Threads
threading in jms
Taking advantage of multiprocessing in game programming
what is the best way to run a schedule??
Making a database connection inside a thread
Timers & TimerTasks