문제

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

도움이 되었습니까?

해결책

... 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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top