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.