Reputation: 2661
I have a requirement where I have to persist some data in a table and the persisting may take sometime. Basically I want to persist a log. I don't want the execution to wait till the persisting finishes.
I know I have to use threads to accomplish this task and I know that it is discouraged to create threads in an enterprise application.
So I started reading about worker manager and understood and tried a sample program in websphere application server 8.5.
I used asynchbeans.jar from websphere and now I am bothered that I am writing vendor specific code.
Then I came across commonj work api which is described in oracle java documentation. Now I am thinking to use commonj api from fabric3.
My doubt is, is there a better way to accomplish the same task? An EJB way? Or work manager is good for my requirement?
Upvotes: 5
Views: 4290
Reputation: 18050
If you need to be sure that all your log entries are safely written, then you probably should use JMS with persistent messages. Otherwise you could use @Asynchronous
EJB methods.
Upvotes: 0
Reputation: 33956
You have some options:
@Asynchronous
methods. Requires using EJBs (unwanted complexity for some).lookup("java:...")
, JPA, UserTransaction, etc.), then you should be fine.Upvotes: 7
Reputation: 597
JavaEE7 has the managed executor, that you can try. You can spawn a task with it, and recieve managed callbacks in a handler. This is part of EE standard and should be platform agnostic.
See JDoc here:
http://docs.oracle.com/javaee/7/api/javax/enterprise/concurrent/ManagedExecutorService.html
Upvotes: 4