Polling the Status of the original Java EE Problem - How?

I am currently working on a web application that needs to import data and do some processing. It might take a while (maybe in the range of "a few minutes" once datasets grow), so we run it in the background - and now it's time to show the status in the interface, not the tails of the log files :)

The frontend is using Angular, connected to REST Endpoint Calling Services (JAX-RS) in EJBs that run over JPA. Works in JBoss EAP 6.4 / AS 7.5 (EE6). Standard stuff, but this is my first time doing Java EE.

Regarding request status, polling the REST endpoint periodically - we don't need fancy stuff like websockets. However, we need to maintain multiple background jobs as well as information consisting of runstate (run / done / error), progress, and error list.

So, I have two questions:

1) Is there a better way to start a background task than calling the @Asynchronous EJB method?

2) What options do I have for tracking background tasks, and which is most appropriate?

My first idea was to keep the HashMap, but this quckly ended up looking like too much manual (and fragile) code with concurrency and life issues - and I prefer not to reinvent the wheel. It looks like JPA is the safest choice, but it seems a bit awkward for unstable state information.

I'm obviously not the first person to run into these problems, but my google-fu is missing right now :)

+3


source to share


1 answer


Tasks can be started using @Asynchronous

or using JMS@MessageDriven

From java-ee-7, ManagedExecutorService is also an option.



The tasks will then update their own state, which is stored in the ConcurrentHashMap inside the @Singleton

EJB.

If you are in a clustered environment, the state of the tasks is better preserved with JPA as @Singleton is not for the whole cluster

+2


source







All Articles