2

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?

kosgeinsky
  • 508
  • 3
  • 21
  • When you say a MessageListener, do you specifically mean something besides an MDB? If so, that is probably the issue. – Scott Kurz Jul 03 '17 at 11:03

1 Answers1

1

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.

Scott Kurz
  • 4,985
  • 1
  • 18
  • 40
  • Thank you Scott, I surely had gaps in my understanding of the EE environment. My MessageListener was running as `@javax.inject.Singleton` instance. Your three paragraphs have also answered more of my questions in mind. – kosgeinsky Jul 04 '17 at 09:51