JBoss Community

Job manager/dispatcher pattern

created by Bernard Labno in EJB3 - View the full discussion

Hello

 

In my app there are some long running tasks that can be started from web front-end. Admin should see progress of those tasks in the same front-end.

What is the best approach to implement this?

 

Right now I have 1 ApplicationScoped JobManager and ~20 task executors running on separate JVM's (simple standalone apps). Those executors periodically (fast) pool JobManager for jobs through JAX-RS.

JobManager must know which job is executed by which executor so that it's not done twice. Also that information must be persistent (in case of JobManager crash/restart).

{code:lang=java}

public String assignJob(String executorId) {

    Job job = get1stUnassignedJobFromDB();

    job.setExecutorId(executorId);

    saveJobInDB(job);

    return job.getId();

}{code}

 

The problem is that sometimes executor 1 gets job A, the transaction doesn't get commited yet and the executor 2 also get's the same job.

Reply to this message by going to Community

Start a new discussion in EJB3 at Community