Question

I'm using glassfish with hibernate, spring, and jpa for data coming into our system and displaying data to the customer.

However, I also have the need to have multiple jobs run every minute to calculate data based on the incoming data.

But I never know the number of jobs and they can change at any time since they're coming from the database. We have x number of customers, and each customer can have 1 to many jobs.

So what I really need to do is:

  1. read from the table to get the number of jobs to run
  2. run each of those jobs every minute
  3. if a job is removed from the table, stop processing that job
  4. if a job is added to the table, add a new job to the list.
  5. each of these jobs will read from a table, do some calculations, and then write to a table with their results.

I've read up on some of the tools out there (quartz, ScheduledExecutorService etc) but does any actually provide this functionality? Or do I have to write my own?

Was it helpful?

Solution

I would start with spring's TaskScheduler:

http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/scheduling.html#scheduling-task-scheduler

But no matter what you use you're going to have to write a non-trivial amount code to support all of this. You'll have to support things like loading all tasks on server startup, ensuring tasks only run on one server (if the app is deployed to multiple glassshish instances), monitoring DB table for deleted users/jobs, etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top