Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

TimerTask, scheduleAtFixedRate doesn't work parallel

Thread view: 
tkonrath - 13 Oct 2005 09:20 GMT
Hi.

I have a problem according to the TimerTask - functionality of Java
1.4.2.

I have two timer-tasks which I want to start at the same time each day
(e.g. at 1 a.m.) in my web-application. I configured both well. I used
the scheduleAtFixedRate method to from the Timer class, because I must
be sure that these tasks are not running during the day when a lot of
users are online. So using the method schedule is not possible for me.

I have recognized that the timer tasks are not running parallel. They
are called like step by step.

So may question is, why are they doing so? I have not found any
information about this behaviour in the Internet.

Is it possible to execute timer tasks parallel using
scheduleAtFixedRate or is it just impossible?

Thanks for any hints.
cu,
Tom
Thomas Weidenfeller - 13 Oct 2005 09:35 GMT
> I have recognized that the timer tasks are not running parallel. They
> are called like step by step.
>
> So may question is, why are they doing so? I have not found any
> information about this behaviour in the Internet.

Really? From the Timer API documentation (emphasis by me):

"Corresponding to each Timer object is a single background thread that
is used to execute all of the timer's tasks, *sequentially*."

In general, I would recommend to use the operating system specific
feature to schedule such tasks, and not re-inventing the wheel if not
absolutely necessary.

If you really want a Java solution, there is some scheduling frame work
out there which you could either use or study to build your own:

http://www.opensymphony.com/quartz/

/Thomas
Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/

tkonrath - 17 Oct 2005 09:06 GMT
Thanks for your answer and your "emphasis" of the Timer API
documentation. Somehow I haven't read this part of the documentation...

We don't want to use a scheduling frame work because the timer tasks
are just a very small part of our product and up to now it is no big
problem that they are processed sequentially.

But when it will be a real problem for us, we will might use the
scheduling frame work you mentioned or we will just use a own Timer for
each task as Tom Hawtin mentioned it below.

Thanks for your help,
Thomas
Thomas Hawtin - 13 Oct 2005 12:33 GMT
> I have recognized that the timer tasks are not running parallel. They
> are called like step by step.

> Is it possible to execute timer tasks parallel using
> scheduleAtFixedRate or is it just impossible?

There is one thread per Timer. So if you schedule multiple tasks with a
single timer, they will be executed one-by-one. The easy solution is to
use multiple timers. Alternatively, immediately the task is fired, pass
it off to a thread pool.

If you move to 5.0 (it has been out for a year already), then the
concurrency library offers more sophisticated features.

http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorSe
rvice.html


If you are sticking to 1.4 for not, but will be upgrading to 5.0, there
is a backport of nearly all the java.util.concurrent API.

http://www.mathcs.emory.edu/dcl/util/backport-util-concurrent/

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Roedy Green - 17 Oct 2005 11:45 GMT
>I have recognized that the timer tasks are not running parallel. They
>are called like step by step.

See http://mindprod.com/jgloss/timer.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.