ScheduledThreadPoolExecutor long running tasks should not be Queued up

View: New views
2 Messages — Rating Filter:   Alert me  

ScheduledThreadPoolExecutor long running tasks should not be Queued up

by sankar adabala :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Iam using STE for polling a large set of devices.STE works fine and scales up well.But i noticed the following.

Q1)
Suppose a TaskA is scheduled repeatedly every 4 minutes and if the Task takes more than 4 minutes and in this case  takes 6 minutes,then the next scheduling is happening at 6th minute.I don't want this behaviour, what i wanted is the task has to be scheduled every 4minutes and the absolute scheduling time should be a multiple of 4.

Is there a mechanism in STE to specify a task to be executed every 4minutes or multiple of 4 in case the task takes more time.


Q2)
What is the tolerance in seconds we can expect in scheduling ,suppose if a task is scheduled every 4 minutes ,does it gets scheduled exactly every 4 minutes or in the range [3 minutes 59 secs to 4 minutes 1 sec].


I have a workaround for Q1.I skip the scheduling if it doesn't fall in the range[3 minutes 59 secs to 4 minutes 1 sec ie a smoothing interval of 1 sec].


please let me know if there are better ways to handle this situation.


Thanks,
Sankar Krishna




      __________________________________________________________
Sent from Yahoo! Mail.
A Smarter Email http://uk.docs.yahoo.com/nowyoucan.html

_______________________________________________
Concurrency-interest mailing list
Concurrency-interest@...
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest

Re: ScheduledThreadPoolExecutor long running tasks should not be Queued up

by Joe Bowbeer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, May 20, 2008 at 11:15 PM, sankar adabala wrote:

I am using STE for polling a large set of devices.STE works fine and scales up well.But i noticed the following.

Q1)
Suppose a TaskA is scheduled repeatedly every 4 minutes and if the Task takes more than 4 minutes and in this case  takes 6 minutes,then the next scheduling is happening at 6th minute.I don't want this behaviour, what i wanted is the task has to be scheduled every 4minutes and the absolute scheduling time should be a multiple of 4.

Is there a mechanism in STE to specify a task to be executed every 4minutes or multiple of 4 in case the task takes more time.


Q2)
What is the tolerance in seconds we can expect in scheduling ,suppose if a task is scheduled every 4 minutes ,does it gets scheduled exactly every 4 minutes or in the range [3 minutes 59 secs to 4 minutes 1 sec].


I have a workaround for Q1.I skip the scheduling if it doesn't fall in the range[3 minutes 59 secs to 4 minutes 1 sec ie a smoothing interval of 1 sec].


please let me know if there are better ways to handle this situation.


Thanks,
Sankar Krishna
 

Your workaround sounds OK to me.  It is similar, by the way, to the sample code in the TimerTask doc that punts if the scheduled execution time was too far in the past.

Concerning punctuality, the scheduled executor will have the best chance if you allocate enough threads (see corePoolSize) such that there's always an idle thread when the next task should begin.  One thread for each long running task in your case.

--Joe
_______________________________________________
Concurrency-interest mailing list
Concurrency-interest@...
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
LightInTheBox - Buy quality products at wholesale price