문제

I have an MDB that processes different types of messages (Object Messages). I want to keep a track of the number of messages received by the MDB and as well as keep count of the type of the messages received.

Although my MDB is distributed across multiple JVMs, I am fine keeping track of the count at individual JVM.

Using static variables is discouraged in EJB, so other alternatives do we have?

도움이 되었습니까?

해결책

One idea:

A @Singleton EJB comes to mind. I would call it Statistics and keep all kinds of statistics there. Each time a Xxx event, that requires statistics, occurs, a addToXxxCount() method could be called. The actual count is available from the corresponding getXxxCount(). It would require read locks on getXxxCount() methods and write locks on addToXxxCount() (see concurrency for singleton EJBs). Alternatively, you can synchronize yourself.

The variable that actually keeps track of the count (int or long) is non-static and the container guarantees the EJB is intantiated only once. And you get a central point of reference for all your statistics.

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