The days of EJB’s being the center of the Java EE universe are coming to an end. CDI is increasingly becoming the de facto component framework, due to its flexibility and lack of legacy. Starting in Java EE 7 and continuing in 8, the Java EE platform is migrating to enable all of EJB’s best features to be usable in the CDI world. In this session, you’ll learn implementation-level details on how they relate to each other, where we are in the EJB/CDI alignment story, what trade-offs you might need to make, and what you have to gain from making the transition. You will walk out with runnable examples and vendor-level insights. This is the perfect session for heavy EJB users looking to keep up with Java EE’s transition to CDI.
5. JavaOne
@dblevins @tomitribe#EJBCDI
CDI Behind the Scenes
• Achieved through sneaky interceptor trick
• Caused major delay to the Java EE 6 delivery
• Almost didn’t make it
• Criticized for going too far
• Stepped on EE toes (spec overlap)
• Stepped on SE toes (too “enterprisey”)
6. JavaOne
@dblevins @tomitribe#EJBCDI
CDI Rifts
• Creation of @ManagedBean spec at EE level
• Fuzzy aim at unifying EE component models
• Effort to not lose ground in EE
• Too ambiguous
• Creation of @Inject spec at SE level
• Fuzzy aim at being simpler version of the standard
• Effort to not lose ground in SE
• Too simple, no spec
9. JavaOne
@dblevins @tomitribe#EJBCDI
Result for EJB?
• Java EE 7
• Focus on realignment: @Transactional
• Java EE 8
• First spec round with no new EJB JSR
• Realignment stalled
• Awkward relationship
13. JavaOne
@dblevins @tomitribe#EJBCDI
Lifecycle Lineup
• @Singleton
• same as CDI @ApplicationScoped
• @Stateful
• applies to any CDI Scope, not just @SessionScoped
• @Stateless
• no CDI equivalent
• @RequestScoped sort of close(ish)
16. JavaOne
@dblevins @tomitribe#EJBCDI
Common Mistakes you will make
• Not putting a beans.xml in your app (Java EE 6)
• No CDI for you!
• Not understanding @Typed
• Psst, think @Local from EJB
• Bites you when using @Produces
• Not understanding what Dependent and NormalScope
• Dependent == plain object
• NormalScoped == proxied object
• Bites you when creating custom scopes
17. JavaOne
@dblevins @tomitribe#EJBCDI
Biggest benefits of CDI
• Very active and open expert group
• Fully extendable
• Beans can be added at runtime
• Fully Open Source
• Spec is open source
• All implementations are open source
• Compliance test (TCK) suite is open source
23. JavaOne
@dblevins @tomitribe#EJBCDI
Observations - What happens?
• More work for servers to check for mistakes
• More work for IDEs to check for mistakes
• New users won’t know which to use and where
• Old users won’t remember how they are different
• One more place for us all to make mistakes and be confused
28. JavaOne
@dblevins @tomitribe#EJBCDI
Schedule
• @Schedule
• Effectively Cron -- schedule invocations by minute or date, etc.
• Usable by
• @Stateless
• @Singleton
• Not @Stateful
• Alignment
• Strong Candidate
• Could be a challenge -- timers are stateless, scopes are not
29. JavaOne
@dblevins @tomitribe#EJBCDI
Locking
• @Lock(READ) / @Lock(WRITE) / @AccessTimeout
• Allows for synchronization of methods without complex code
• Usable by
• @Singleton
• Not @Stateless
• Not @Stateful
• Alignment
• Medium Candidate
• Applying to CDI possibly easier than EJB