views:

160

answers:

5

I have stacked for weeks trying to find a solution on this. Im coming back over and over again to the same. Java 's ScheduledThreadPoolExecutor alternatives... but nothing does this.

What I want is to execute jobs syncrhonized/serially inside a scheduler, having lot of schedulers doing that independentely from each other, backed by one single threadpool...

I have a server application in java and what I need is to create hundreds and thousands of schedulers.

I want each scheduler to execute its jobs serially and syncrhonized.

All schedulers can run concurrently and independently but I also need to limit the number of the threads of all schedulers by using a threadpool (not threadpool per scheduler, but one threadpool for ALL schedulers!). Also the ability to pause/resume jobs and put them inside groups would be great. any solutions? thanks in advance!

A: 

If you want jobs to execute serially within a ScheduledThreadPoolExecutor you just create an aggregated job who perform each of the actual jobs in a serial fashoin and submit it to your ScheduledThreadPoolExecutor. Though if you need thousands of schedulers to run at the same time, but still limit the no. of threads , you could get in trouble - atleast if the jobs takes too long to execute so you start slipping on your scheduling.

I'd say you should take a look at Quartz for handling this, as it'll handle most of the gory details of scheduling and jobs.

nos
Hello nos!Thanks for answering.I'm interested on the solution you suggest using ScheduledThreadPoolExecutor and aggregated jobs. It is something that I was thinking sometimes but I have some serious questions on the implementation.1. how to create an aggregated job that contains delayed actual jobs ?2. how can this aggregated job perform each one of them... looping every time in the actual jobs list to see which one needs to be executed?3. Is this unefficient? how should it be submitted (the aggregated job) to the ScheduledThreadPoolExecutor? using a delay? or not?Thanks! ))
alexei
1. By an aggregated job, I'm thinking of a sequence of jobs that runs serially, one immediately after the other. It sounds like you have a series of jobs that have different delays - do you really need these to be "serially" executed ? 2. Don't do that. 3. If you want the jobs to execute after a certain delay, use a delay, otherwise don't.
nos
First of all excuse me for my english.1. by saying serial execution I mean synchronized execution between tasks. I dont want my actual jobs to be executed concurrently.2. the question was how to do it. if not by looping in a list of tasks then how?3. ok about this one ;)
alexei
A: 

I'm trying to find such a solution myself. In the .Net world, you have a centrally shared thread pool provided by the system, which dynamically expands and shrinks. My situation is that I have lots of low frequency maintenance type of jobs, a single thread should be able to handle them all.

I guess you can have a singleton Executor (thread pooled version) somewhere and always use it to schedule tasks. This would mimic .Net behavior.

Xian Xu
A: 

Have you considered using HawtDispatch and a lot of serial queues? It sounds like it might do as you want, with a simple API. I have been thinking of trying it myself. Akka project uses it as I understand it.

Vanessa Williams
Actually, I meant to say "Akka".
Vanessa Williams
You can use the `edit` link to edit your answers.
BalusC
A: 

Maybe a separate scheduler such as Quartz Scheduler would server your needs?

bemace
A: 

dhtmlx scheduler works for me but this work with his own connection with db here is source and samples http://dhtmlx.com/docs/products/dhtmlxScheduler/index.shtml?mn and his java connector www.dhtmlx.com/x/download/regular/dhtmlxConnector_v09_java.zip

mavirroco