SlideShare a Scribd company logo
David Blevins | Apache

Tomcat to JavaEE with
   Apache TomEE
@dblevins
dblevins@apache.org

@ApachTomEE / #TomEE
http://tomee.apache.org
What is Apache TomEE?
Tomcat + JavaEE = TomEE
• Java EE 6 Web Profile certified
• Tomcat through and through
• All Apache components
  –   OpenJPA
  –   OpenWebBeans
  –   OpenEJB
  –   MyFaces
• Core Values
  – Be small
  – Be certified
  – Be Tomcat
Flavors of TomEE
• Apache TomEE Web Profile (Java EE 6 Certified)
  –   CDI
  –   EJB
  –   JPA
  –   JSF
  –   Bean Validation
• Apache TomEE Plus
  – JAX-RS
  – JAX-WS
  – JMS
• Embedded Apache TomEE
Basic Stats
• Size
  – 27mb
• Memory usage
  – very little required
  – passes TCK with default 64mb
• Agility:
  – Eclipse deploy ~700ms
  – embedded test 2-4 seconds
Certification
• Certified on Amazon EC2
   –   t1.micro linux images,
   –   100 spot instances
   –   613mb memory
   –   64mb used, 549mb free
   –   t1.micros have slow disks, memory is critical
• Current certified OSs
   – Amazon Linux AMI 2011.09, EBS boot, EC2 t1.micro
   – Amazon Linux AMI 2011.09, EBS boot, EC2 m1.small
   – Amazon Linux AMI 2011.09, EBS boot, EC2 c1.medium
• Runs daily
• Got a Cloud?
   – Donate time!
“There is also one point to note. TomEE is insanely fast! ”
    -- Łukasz Budnik, CXF JAX-RS on Apache TomEE @ DZone, May 23rd 2012



“From an architect that switched from <XXX> to Tomee. I can
tell you Tomee kicks <XXX>'s ass in every way. Memory,
speed, reliability, validation, you name it.”
                                    -- Zeeman, User List, July 3rd 2012


“If you are concerned about performance and footprint, but
can accept that you'll have to solve problems yourself, go
TomEE. (TomEE seems to be _much_ faster than <XXX>)”
                             -- Jonathan Fisher, User List, July 3rd 2012
Gaps in Tomcat
Gaps in Tomcat
• No Transaction support
• No Connection Pooling support
  – Pooling should be transactional
• No Integrated Security
• No support for Global JNDI
  – java:module
  – java:app
  – java:global
• No support for @DataSourceDefinition
• No support for new <env-entry> types:
  – java.lang.Class
  – Enums
Gaps in Tomcat
• No @Resource
    –   UserTransaction
    –   BeanManager
    –   Validator
    –   ValidatorFactory
    –   Topic/Queue
    –   ConnectionFactory
•   No @PersistenceUnit
•   No @PersistenceContext
•   No @Inject
•   No @EJB
•   No @WebServiceRef
Migration Issues
Building your own app server
• Including API jars in the webapp
  – JPA API
  – JSF API
  – etc.
• Including implementations in webapp
  – Mojarra (works in trunk)
  – Bitronix/Atomikos
• Non-compliant DataSource and JPA
  – too many years of Do It Yourself
  – providers not enforcing rules
(Mis)Information
• Gaps in Knowledge
  – “that other stuff”
• Misinformation
  – don’t use X, it’s heavy
• Leads to...
  – let’s build own own heavy X!
• Bites you
  – non-portable apps
  – lacks tens of thousands of tests
  – lacks shared experience
Closing Gaps in Knowledge
You can’t use this




• unless you understand
  – JTA Transactions
  – Container-managed EntityManagers
  – Container-managed DataSources
  – How to get references to these, properly!
Not Just EJBs
• Components with Transaction support
  – Servlets
  – JSP
  – JSF Managed Beans
  – CDI
  – EJB
  – JAX-RS REST Services
  – JAX-WS Web Services
What are Transactions?
“Undo”
From Tomcat to Java EE, making the transition with TomEE
From Tomcat to Java EE, making the transition with TomEE
From Tomcat to Java EE, making the transition with TomEE
Controlling Transactions
• javax.transaction.UserTransaction
  – Manual approach
  – Any JavaEE component
• @javax.ejb.TransactionAttribute
  – Class or method annotation
  – EJB only
• @javax.transaction.Transactional
  – Class or method annotation
  – Any JavaEE component*
  – Coming in JavaEE 7
Transaction Hooks
• SessionSynchronization
  – @AfterBegin
  – @BeforeCompletion
  – @AfterCompletion
• Events
  – @Observes(during=IN_PROGRESS)
  – @Observes(during=BEFORE_COMPLETION)
  – @Observes(during=AFTER_COMPLETION)
     • @Observes(during=AFTER_SUCCESS)
     • @Observes(during=AFTER_FAILURE)
From Tomcat to Java EE, making the transition with TomEE
“Undo” aware Resources
•   DataSource
•   EntityManager
•   Sending JMS Messages
•   Receiving JMS Messages
•   Timers & @Schedule
•   (more via Java EE connectors)
    [Some restrictions apply. Offer void where prohibited. Container-
    provided resources required. Must be 18 years or older to apply]
More specifically
How does it work?
TOP SECRET
(authorized personnel only)
This is not a pipe
Not the real thing
The EntityManager You Get
From Tomcat to Java EE, making the transition with TomEE
continued...
The DataSource You Get
From Tomcat to Java EE, making the transition with TomEE
better than a pipe
...better than the real thing




• thread-safe
• undo-aware
• leak-free
All boils down to...
“hashmap”




“listeners”
...but
Won’t work with any of this
• DataSource
  – DriverManager.getConnection(...)
  – new FooDataSource()
  – autocommit = true
• EntityManager
  – PersistenceProvider.createEntityManag...
  – EntityManagerFactory.createEntityManager
  – EntityTransaction
Avoid Do It Yourself
Rule
• If you didn’t get it from the Container
  – it isn’t usable with UserTransaction
  – connections may leak
  – memory may leak
• Even then there are some BIG notes
  – EntityManagerFactory
     • not usable with UserTransaction
  – <persistence-unit=RESOURCE_LOCAL>
     • not usable with UserTransaction
From Tomcat to Java EE, making the transition with TomEE
Common Migration Issues
     & Mistakes
Wrong
Wrong
Wrong
Still Wrong
From Tomcat to Java EE, making the transition with TomEE
The worst of them all
this...
or this...
with THIS!
darn defaults!
There we go
JPA Rules
• RESOURCE_LOCAL
  – Persistence.createEntityManagerFactory
  – @PersistenceUnit EntityManagerFactory
  – <non-jta-data-source>
• JTA
  – @PersistenceContext EntityManager
  – <jta-data-source>
  – <non-jta-data-source>
• No other combinations are valid
Good
• Valid RESOURCE_LOCAL usage
Better
• Valid RESOURCE_LOCAL usage
Best
• Valid JTA usage
DataSource
• Declare
  – in tomee.xml
  – in META-INF/resources.xml
  – via @DataSourceDefinition
• Retrieve
  – @Resource
  – <resource-ref>
• Undo-aware and pooled
Declaring
• <tomee-home>/conf/tomee.xml




• WEB-INF/resources.xml
Recap
Recap
• Use if you need “undo”
• Transactions not heavy
   – Thread safe management
   – Help prevent Leaks
   – Enhance programming
• More than a TransactionManager
   – TransactionManagers do nothing alone
   – Resources must cooperate
• Don’t Do It Yourself
   – Use container-provided resources
   – no need to re-invent the wheel
Recap
• Components with Transaction support
  – Servlets
  – JSP
  – JSF Managed Beans
  – CDI
  – EJB
  – JAX-RS REST Services
  – JAX-WS Web Services
Recap
• Transactional Resources
  – DataSource
  – EntityManager
  – Sending JMS Messages
  – Receiving JMS Messages
  – Timers & @Schedule
  – (more via Java EE connectors)
Questions?
Thank You!

        @dblevins
http://tomee.apache.org

More Related Content

PDF
Java EE | Apache TomEE - Java EE Web Profile on Tomcat | Jonathan Gallimore
PDF
2011 JavaOne Apache TomEE Java EE 6 Web Profile
PDF
Java EE 7, what's in it for me?
PDF
Apache TomEE, Java EE 6 Web Profile on Tomcat - David Blevins
PDF
Eureka Moment UKLUG
PDF
Social Connections 2015 CrossWorlds and Domino
PDF
The Fast, The Slow and the Lazy
PPTX
Php push notifications
Java EE | Apache TomEE - Java EE Web Profile on Tomcat | Jonathan Gallimore
2011 JavaOne Apache TomEE Java EE 6 Web Profile
Java EE 7, what's in it for me?
Apache TomEE, Java EE 6 Web Profile on Tomcat - David Blevins
Eureka Moment UKLUG
Social Connections 2015 CrossWorlds and Domino
The Fast, The Slow and the Lazy
Php push notifications

What's hot (20)

PDF
Profiling JavaScript Performance
KEY
Fast, concurrent ruby web applications with EventMachine and EM::Synchrony
PDF
HyperLight Websites
ODP
Eureka moment
PDF
HH.JS - State of the Automation
PDF
Full-Stack Plone Deployment with Ansible
KEY
Plone Deployment (PloneConf Edition)
PPTX
CollabSphere SC 103 : Domino on the Web : Yes, It's (Probably) Hackable
PDF
Building Next Generation Real-Time Web Applications using Websockets
PDF
Enterprise Messaging With Spring JMS
PDF
Beyond Horizontal Scalability: Concurrency and Messaging Using Spring
PDF
What python can learn from java
PDF
ColdFusion builder plugins
PPTX
XPages and Java (DanNotes 50th conference, November 2013)
PDF
10 common cf server challenges
PDF
Engage 2014 OpenNTF Domino API Slides
PDF
BP204 It's Not Infernal: Dante's Nine Circles of XPages Heaven
PDF
Realtime web application with java
PDF
DanNotes 2013: OpenNTF Domino API
PDF
Google app-engine-cloudcamplagos2011
Profiling JavaScript Performance
Fast, concurrent ruby web applications with EventMachine and EM::Synchrony
HyperLight Websites
Eureka moment
HH.JS - State of the Automation
Full-Stack Plone Deployment with Ansible
Plone Deployment (PloneConf Edition)
CollabSphere SC 103 : Domino on the Web : Yes, It's (Probably) Hackable
Building Next Generation Real-Time Web Applications using Websockets
Enterprise Messaging With Spring JMS
Beyond Horizontal Scalability: Concurrency and Messaging Using Spring
What python can learn from java
ColdFusion builder plugins
XPages and Java (DanNotes 50th conference, November 2013)
10 common cf server challenges
Engage 2014 OpenNTF Domino API Slides
BP204 It's Not Infernal: Dante's Nine Circles of XPages Heaven
Realtime web application with java
DanNotes 2013: OpenNTF Domino API
Google app-engine-cloudcamplagos2011
Ad

Similar to From Tomcat to Java EE, making the transition with TomEE (20)

PDF
JavaOne 2011: Migrating Spring Applications to Java EE 6
KEY
Appengine Nljug
PPTX
Top 50 java ee 7 best practices [con5669]
PPT
J2EE Batch Processing
PDF
web component_development
PPTX
Seven Points for Applying Java EE 7
PDF
Advance Java Training in Bangalore | Best Java Training Institute
PDF
Ejb 3 Developer Guide A Practical Guide For Developers And Architects To The ...
PDF
Migrating traditional Java EE Applications to mobile
PPT
Virtual classroom
DOC
J2EE Online Training
PPT
j2ee Building components
DOC
Java online training from hyderabad
PPTX
Move from J2EE to Java EE
PDF
Java Online Training
PDF
Best Java Online Training in India
KEY
A Walking Tour of (almost) all of Springdom
PPTX
Java enterprise paradise
PDF
2000: Making IT Happen with J2EE
DOCX
JavaOne 2011: Migrating Spring Applications to Java EE 6
Appengine Nljug
Top 50 java ee 7 best practices [con5669]
J2EE Batch Processing
web component_development
Seven Points for Applying Java EE 7
Advance Java Training in Bangalore | Best Java Training Institute
Ejb 3 Developer Guide A Practical Guide For Developers And Architects To The ...
Migrating traditional Java EE Applications to mobile
Virtual classroom
J2EE Online Training
j2ee Building components
Java online training from hyderabad
Move from J2EE to Java EE
Java Online Training
Best Java Online Training in India
A Walking Tour of (almost) all of Springdom
Java enterprise paradise
2000: Making IT Happen with J2EE
Ad

Recently uploaded (20)

PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Machine learning based COVID-19 study performance prediction
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Cloud computing and distributed systems.
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
A Presentation on Artificial Intelligence
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Approach and Philosophy of On baking technology
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Per capita expenditure prediction using model stacking based on satellite ima...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Machine learning based COVID-19 study performance prediction
Spectral efficient network and resource selection model in 5G networks
Network Security Unit 5.pdf for BCA BBA.
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Diabetes mellitus diagnosis method based random forest with bat algorithm
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Cloud computing and distributed systems.
The Rise and Fall of 3GPP – Time for a Sabbatical?
A Presentation on Artificial Intelligence
Review of recent advances in non-invasive hemoglobin estimation
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Approach and Philosophy of On baking technology
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
20250228 LYD VKU AI Blended-Learning.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025

From Tomcat to Java EE, making the transition with TomEE

  • 1. David Blevins | Apache Tomcat to JavaEE with Apache TomEE
  • 3. What is Apache TomEE?
  • 4. Tomcat + JavaEE = TomEE • Java EE 6 Web Profile certified • Tomcat through and through • All Apache components – OpenJPA – OpenWebBeans – OpenEJB – MyFaces • Core Values – Be small – Be certified – Be Tomcat
  • 5. Flavors of TomEE • Apache TomEE Web Profile (Java EE 6 Certified) – CDI – EJB – JPA – JSF – Bean Validation • Apache TomEE Plus – JAX-RS – JAX-WS – JMS • Embedded Apache TomEE
  • 6. Basic Stats • Size – 27mb • Memory usage – very little required – passes TCK with default 64mb • Agility: – Eclipse deploy ~700ms – embedded test 2-4 seconds
  • 7. Certification • Certified on Amazon EC2 – t1.micro linux images, – 100 spot instances – 613mb memory – 64mb used, 549mb free – t1.micros have slow disks, memory is critical • Current certified OSs – Amazon Linux AMI 2011.09, EBS boot, EC2 t1.micro – Amazon Linux AMI 2011.09, EBS boot, EC2 m1.small – Amazon Linux AMI 2011.09, EBS boot, EC2 c1.medium • Runs daily • Got a Cloud? – Donate time!
  • 8. “There is also one point to note. TomEE is insanely fast! ” -- Łukasz Budnik, CXF JAX-RS on Apache TomEE @ DZone, May 23rd 2012 “From an architect that switched from <XXX> to Tomee. I can tell you Tomee kicks <XXX>'s ass in every way. Memory, speed, reliability, validation, you name it.” -- Zeeman, User List, July 3rd 2012 “If you are concerned about performance and footprint, but can accept that you'll have to solve problems yourself, go TomEE. (TomEE seems to be _much_ faster than <XXX>)” -- Jonathan Fisher, User List, July 3rd 2012
  • 10. Gaps in Tomcat • No Transaction support • No Connection Pooling support – Pooling should be transactional • No Integrated Security • No support for Global JNDI – java:module – java:app – java:global • No support for @DataSourceDefinition • No support for new <env-entry> types: – java.lang.Class – Enums
  • 11. Gaps in Tomcat • No @Resource – UserTransaction – BeanManager – Validator – ValidatorFactory – Topic/Queue – ConnectionFactory • No @PersistenceUnit • No @PersistenceContext • No @Inject • No @EJB • No @WebServiceRef
  • 13. Building your own app server • Including API jars in the webapp – JPA API – JSF API – etc. • Including implementations in webapp – Mojarra (works in trunk) – Bitronix/Atomikos • Non-compliant DataSource and JPA – too many years of Do It Yourself – providers not enforcing rules
  • 14. (Mis)Information • Gaps in Knowledge – “that other stuff” • Misinformation – don’t use X, it’s heavy • Leads to... – let’s build own own heavy X! • Bites you – non-portable apps – lacks tens of thousands of tests – lacks shared experience
  • 15. Closing Gaps in Knowledge
  • 16. You can’t use this • unless you understand – JTA Transactions – Container-managed EntityManagers – Container-managed DataSources – How to get references to these, properly!
  • 17. Not Just EJBs • Components with Transaction support – Servlets – JSP – JSF Managed Beans – CDI – EJB – JAX-RS REST Services – JAX-WS Web Services
  • 23. Controlling Transactions • javax.transaction.UserTransaction – Manual approach – Any JavaEE component • @javax.ejb.TransactionAttribute – Class or method annotation – EJB only • @javax.transaction.Transactional – Class or method annotation – Any JavaEE component* – Coming in JavaEE 7
  • 24. Transaction Hooks • SessionSynchronization – @AfterBegin – @BeforeCompletion – @AfterCompletion • Events – @Observes(during=IN_PROGRESS) – @Observes(during=BEFORE_COMPLETION) – @Observes(during=AFTER_COMPLETION) • @Observes(during=AFTER_SUCCESS) • @Observes(during=AFTER_FAILURE)
  • 26. “Undo” aware Resources • DataSource • EntityManager • Sending JMS Messages • Receiving JMS Messages • Timers & @Schedule • (more via Java EE connectors) [Some restrictions apply. Offer void where prohibited. Container- provided resources required. Must be 18 years or older to apply]
  • 28. How does it work?
  • 30. This is not a pipe
  • 31. Not the real thing
  • 38. ...better than the real thing • thread-safe • undo-aware • leak-free
  • 39. All boils down to...
  • 42. Won’t work with any of this • DataSource – DriverManager.getConnection(...) – new FooDataSource() – autocommit = true • EntityManager – PersistenceProvider.createEntityManag... – EntityManagerFactory.createEntityManager – EntityTransaction
  • 43. Avoid Do It Yourself
  • 44. Rule • If you didn’t get it from the Container – it isn’t usable with UserTransaction – connections may leak – memory may leak • Even then there are some BIG notes – EntityManagerFactory • not usable with UserTransaction – <persistence-unit=RESOURCE_LOCAL> • not usable with UserTransaction
  • 47. Wrong
  • 48. Wrong
  • 49. Wrong
  • 52. The worst of them all
  • 58. JPA Rules • RESOURCE_LOCAL – Persistence.createEntityManagerFactory – @PersistenceUnit EntityManagerFactory – <non-jta-data-source> • JTA – @PersistenceContext EntityManager – <jta-data-source> – <non-jta-data-source> • No other combinations are valid
  • 62. DataSource • Declare – in tomee.xml – in META-INF/resources.xml – via @DataSourceDefinition • Retrieve – @Resource – <resource-ref> • Undo-aware and pooled
  • 64. Recap
  • 65. Recap • Use if you need “undo” • Transactions not heavy – Thread safe management – Help prevent Leaks – Enhance programming • More than a TransactionManager – TransactionManagers do nothing alone – Resources must cooperate • Don’t Do It Yourself – Use container-provided resources – no need to re-invent the wheel
  • 66. Recap • Components with Transaction support – Servlets – JSP – JSF Managed Beans – CDI – EJB – JAX-RS REST Services – JAX-WS Web Services
  • 67. Recap • Transactional Resources – DataSource – EntityManager – Sending JMS Messages – Receiving JMS Messages – Timers & @Schedule – (more via Java EE connectors)
  • 69. Thank You! @dblevins http://tomee.apache.org