java ee - Refresh data in stateless EJB -


Is there a function that is seen every time EJB? I need to refresh some data before any method is told.

First you will have to distinguish between stateless and stateful EJB.

  • Stateless EJB is well, stateless , and should not contain data. App The server can decide to destroy or rebuild it at any time. You can not really put any reference for a specific example which is made when it is viewed as App. The server maintains a pool of EJB, and one of these is used for allocation.

  • The state can contain data in EJB. You capture the context of a specific example, which is made from when the beans are seen. Callback methods can be specified with @PostConstruct or @PreDestroy (These callbacks are also present for stateless EJBs but less sensible).

He said, if you need to do something before any method, then I suggest that you use Interceptor (< Using Code> @Interceptor, , Stateless and State EJBs works). Just with AOP, you get a chance to do something before and after the Bean method, such as refreshing the cache.


Comments