Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the @Resource annotation applied when a Stateless EJB is deserialized?

Is the @Resource annotation on a method applied when an EJB is deserialized? I have a EJB Timer thats persisted by the container and would like to know if the transient TimerService (it's not serializable) will be injected again when the EJB is deserialized.

like image 894
n002213f Avatar asked Nov 24 '10 11:11

n002213f


People also ask

Which annotation is used for stateless EJB?

Use @Stateless annotation to signify it a stateless bean. EJB Container automatically creates the relevant configurations or interfaces required by reading this annotation during deployment.

Are stateless EJB thread safe?

Working with EJBs without any further configuration is thread-safe regardless whether you are invoking one method or multiple methods concurrently.

What is stateless EJB?

Stateless Beans A stateless session bean is a type of enterprise bean which is commonly used to do independent operations. It does not have any associated client state, but it may preserve its instance state.


1 Answers

Perhaps this articles help:

  • Stateless Session Bean: the stateless session EJB is injected at creation time, and keeps it's resources along its life time.

  • Stateful Session Bean: It seems that the dependency injection only occurs at creation time. Anyway, after activation, the @PostActivate callback Handler is invoked, where you could recover your transient elements.

Edit for adding the Java EE Tutorial link on this subject, which confirms what is exposed:

  • The Life Cycles of Enterprise Beans

So, as a conclusion, the answer is no, the container won't inject again your transient resources after activation, but you can implement a PostActivate handler to do it by your own means.

like image 65
Tomas Narros Avatar answered Nov 14 '22 22:11

Tomas Narros