java - Concurrent periodic task running -


i'm trying find best solution periodic task running in parallel. requirements:

  1. java (spring w/o hibernate).
  2. 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:

  1. taskimporter thread polling tasks db (via tasksdao.findtoprocess()) , submitting them queue.
  2. java.util.concurrent.threadpoolexecutor running tasks (from queue) in parallel.

the tricky part of architecture tasksdao.findtoprocess():

  1. 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).
  2. 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?

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

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -