javajmsglassfish-4.1activemq-artemisjsr352

Batch job is stuck at STARTING when submited from a JMS Listener onMessage()


I'm trying to start batch jobs according to JSR 352 specifications using JobOperator obtained from BatchRuntime in an onMessage(...) method in a JMS MessageListener.

JobOperator jobOperator = BatchRuntime.getJobOperator();
Properties props = new Properties();
props.setProperty("sourceFile", "data_file.csv");
jobOperator.start("batchTask", props);

The result is that the job execution is stuck at STARTING. When I try to stop the task from the same thread, it is similarly stuck at STOPPING.

Starting the same job from a plain HttpServlet it runs to completion immediately. Why is this so?


Solution

  • You should use an MDB to consume a JMS message within an EE application server, not your own MessageListener. (See here.)

    Batch needs to run on a managed thread so that EE contexts are available so that EE APIs such as the ManagedExecutorService used as the batch "thread pool" will function correctly.

    There will also be potential issues with other EE APIs besides batch (and potentially other app server features) when using non-managed threads, which is why the MDB is the necessary approach here.