java - Concurrent periodic task running -
i'm trying find best solution periodic task running in parallel. requirements:
- java (spring w/o hibernate).
- tasks being managed front-end application , stored in mysql db (fields:
id
,frequency
(in seconds), <other attributes/settings task scenario
>). -- crontab,frequency
(seconds) field, instead of minutes/hours/days/months/days of weeks.
i'm thinking about:
taskimporter
thread polling tasks db (viatasksdao.findtoprocess()
) , submitting them queue.java.util.concurrent.threadpoolexecutor
running tasks (from queue) in parallel.
the tricky part of architecture tasksdao.findtoprocess()
:
- how know tasks time run right now?
- i'm thinking
next_run
task field, populated (update tasks set next_run = timestampadd(second, now(), frequency) id = ?
straight after selection (select * tasks next_run null or next_run <= now() update
). problem: have run lots of updates lots of select'ed tasks (update each task or bulk update) + concurrency problems (see below).
- i'm thinking
- ability run several concurrent processing applications (cloud), using/polling same db.
- all of concurring processing applications must run concrete task once. must lock select's other apps, until app finishes updating (
next_run
) of selected tasks. problem: locking production table (front-end app) slow things down. table mirror?
- all of concurring processing applications must run concrete task once. must lock select's other apps, until app finishes updating (
i love simple , clean solutions , believe there's better way implement processing application. see any? :)
thanks in advance.
edit: using quartz scheduler/executor not option because of syncing latency. front-end app not in java , not able interact quartz, except webservice-oriented solution, not option too, because front-end app has more data associated mentioned tasks , needs direct access data in db (read+write).
i suggest using scheduling api quartz rather using home grown implementation. provides lot of api implementation of logic , convenience. have better control on jobs. http://www.quartz-scheduler.org/ http://www.quartz-scheduler.org/docs/tutorial/index.html
Comments
Post a Comment