You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@openwebbeans.apache.org by Matthew Broadhead <ma...@nbmlaw.co.uk> on 2017/08/30 07:39:09 UTC

CDI version of EJB Singleton?

Hi,
I have converted most of my old EJB stuff to CDI but the one thing that 
is still using EJB are these @Asynchronous @Singleton things. Please 
could anyone provide a "CDI way" example to accomplish the same result?

import javax.ejb.AccessTimeout;
import javax.ejb.Asynchronous;
import javax.ejb.Lock;
import javax.ejb.LockType;
import javax.ejb.Singleton;

@Singleton
public class SomethingAsync {

     @Asynchronous
     @Lock(LockType.READ)
     @AccessTimeout(-1)
     public void addJob(String value) {
         // this job takes a while
         doSomething(value);
     }

     public void doSomething(String value) {
        System.out.println(value);
     }
}


Re: CDI version of EJB Singleton?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi Matthew,

DeltaSpike has this feature but it is not built-in in the spec:
https://deltaspike.apache.org/documentation/core.html#AsynchronousOperations


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://blog-rmannibucau.rhcloud.com> | Old Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

2017-08-30 9:39 GMT+02:00 Matthew Broadhead <ma...@nbmlaw.co.uk>
:

> Hi,
> I have converted most of my old EJB stuff to CDI but the one thing that is
> still using EJB are these @Asynchronous @Singleton things. Please could
> anyone provide a "CDI way" example to accomplish the same result?
>
> import javax.ejb.AccessTimeout;
> import javax.ejb.Asynchronous;
> import javax.ejb.Lock;
> import javax.ejb.LockType;
> import javax.ejb.Singleton;
>
> @Singleton
> public class SomethingAsync {
>
>     @Asynchronous
>     @Lock(LockType.READ)
>     @AccessTimeout(-1)
>     public void addJob(String value) {
>         // this job takes a while
>         doSomething(value);
>     }
>
>     public void doSomething(String value) {
>        System.out.println(value);
>     }
> }
>
>