How to create threads in Java EE?

I have a requirement when I need to save some data in a table, and saving may take some time. Mostly I want to keep a log. I do not want the execution to wait for the continuation.

I know that I need to use threads to complete this task, and I know that it is not recommended to create threads in a corporate application.

So, I started reading about the employee manager and realized and tried the sample program on the websphere 8.5 application server.

I used asynchbeans.jar from websphere and now it bothers me that I am writing specific provider code.

Then I came across the normal api operation, which is described in the oracle java documentation. Now I am going to use commonj api from fabric3.

My doubt is, is there a better way to accomplish the same task? EJB way? Or is a work manager good for my requirement?

+4
source share
3 answers

You have several options:

  • Asynchronous beans. As you mentioned, they are vendor specific.
  • commonj is almost vendor dependent. As far as I know, it was implemented only by IBM WebSphere Application Server and BEA WebLogic. The API has actually been replaced by Concurrency Utilities for Java EE , which is indeed a better choice.
  • EJB @Asynchronous. Requires the use of EJB (for some, undesirable complexity).
  • EJB. EJB, .
  • JMS. , MDB, .
  • . EE , EE (lookup("java:..."), JPA, UserTransaction ..), .
+7

, , , , JMS . @Asynchronous EJB.

0
source

Source: https://habr.com/ru/post/1624256/


All Articles