Question

This is my scenario i have two singleton EJB. The first one receive some data and writes it in a Queue data structure instantiated by the other EJB.

@Singleton
@Startup
public class Client implements IClient {

@EJB
IClientInQueue reporter;
....
@Asynchronous
public void update(String message){
    StatusMessage m = new StatusMessage();
    reporter.addStatusMessage(m);

}


@Startup
@Singleton
public class ClientInQueue implements IClientInQueue {

private ConcurrentLinkedQueue<StatusMessage> statusInQueue;
    addStatusMessage(String m) ..add element to queue

This works fine. Now i want to poll periodically this queue and then make some dispatching operation. My issue is that a i can't use runnable in ejb context. I'm looking to migrate to spring, but first of make this i want to know if i'm missing something. thanks

Was it helpful?

Solution

... now I want to poll periodically this queue..

If you need execute some code periodically, the Java EE specification provides a service called Timer Service that is useful in these cases. This service gives you the posibility to execute your code at a defined interval time.

My issue is that a i can't use runnable in ejb context.

Since Java EE 7 (JSR 236: Concurrency Utilities), exists the possibility to create a managed thread, which allows you run new threads within a Container in a safe way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top