SlideShare uma empresa Scribd logo
1 de 28
Performance Tips and Tricks: Java
  EE, Java Persistence API, and
        JavaServer Faces
Alberto Lemos (Dr. Spock)    Danival Taffarel Calegari
 Senior Software Architect   MATERA Systems Architect
   Globalcode Instructor       Globalcode Instructor




                                       Globalcode – Open4education
Agenda
 Motivation
 Data recovery strategies
   Lazy vs Eager
   Cache
 Web UI Design Strategies
   Conversation Scope
   View Helper + Persistence Service
   Lazy UI Components



                                       Globalcode – Open4education
Objective




  “Present some tips and tricks on web
application development with JSF, Ajax,
               and JPA”



                             Globalcode – Open4education
Motivation
 JavaServer Faces (JSF) is a paradigm change in
 Web development with Java EE;
 It establishes a model for web UI components.
 JSF evolved!
   JSF 1.x (without AJAX) => Ineffective event oriented
   JSF 1.x + AJAX lib => Event oriented
   JSF 2.x => Event oriented
 It's necessary to evolve the development
 techniques on presentation and persistence layers!

                                            Globalcode – Open4education
Agenda
 Motivation
 Data recovery strategies
   Lazy vs Eager
   Cache
 Web UI Design Strategies
   Conversation Scope
   View Helper + Persistence Service
   Lazy UI Components



                                       Globalcode – Open4education
Lazy vs Eager
 Strategies to handle the entity relationships;
 Lazy: it fetches data on demand;
 Eager: it always fetches data.




                                        Globalcode – Open4education
Lazy vs Eager
 Tip: JPA allows for a change from lazy to eager
 using the JP-QL;
   select distinct c from Categoria c join fetch c.produtos
 It runs only one SELECT in the database;
 Join fetch solves the N+1 problem;
 Distinct should be used to avoid duplicated
 results;
 Note: this may cause problems with database
 pagination.

                                            Globalcode – Open4education
Lazy vs Eager
 Tip: Try to paginate in database using lazy
 strategy;
   Use the setFirstResult and setMaxResults methods by
   Query.
 The JPA provider will use native database
 commands to limit the query results;
 Beware: join fetch for 1:N relationships causes
 performance and memory problems.
   WARN: firstResult/maxResults specified with collection
   fetch; applying in memory!

                                           Globalcode – Open4education
Lazy vs Eager
 Tip: Try to use eager whenever bulk processing
 data;
   One common situation is report generation.
 Be careful with memory use;
   Do a previous query to get the ids and limit the results
   with an in clause;
   Use the clear method from EntityManager to remove
   processed objects from memory.




                                             Globalcode – Open4education
Cache
 First level cache
   While the EntityManager is open, it maitains the
   references for all objects loaded by it;
   This cache is erased when the clear method is called.
 Second level cache
   Maintains object references per EntityManagerFactory;
   It is a per-application cache.




                                           Globalcode – Open4education
Cache




        Globalcode – Open4education
Cache
 Trick: By loading related entities into first level
 cache before the main query, performance will
 be greatly improved.
   It can only work with N:1 relationships for entities with a
   small number of instances.
 Example: Fetching products with any filter.
   If there are 200 categories, the lazy strategy should run
   200 queries on the category table;
   Execute a “select c from Category c” before querying for
   products.


                                               Globalcode – Open4education
Cache
 Tip: Use second level cache to save memory
 and to improve performance;
 Choose non-frequent altered entities;
 If an external application changes the database,
 data in the second level cache will become
 outdated.
   Apply a time limit for data expiration.




                                             Globalcode – Open4education
Agenda
 Motivation
 Data recovery strategies
   Lazy vs Eager
   Cache
 Web UI Design Strategies
   Conversation Scope
   View Helper + Persistence Service
   Lazy UI Components



                                       Globalcode – Open4education
The Problem
 DAO + JDBC => open/close connection;
 DAO + Persistence Context => open/close session;




 LazyInitializationException!
                                   Globalcode – Open4education
Old Solution
  OpenSessionInViewFilter Design Pattern;




  New problems!

                                   Globalcode – Open4education
New Problems
 OpenSessionInViewFilter Design Pattern;




 1st REQUEST        2nd REQUEST        Nth REQUEST


 Each request uses a different persistence context;
 Session scoped entities can throw
 LazyInitializationException!

                                      Globalcode – Open4education
Web 1.0
 Request-oriented web applications;




                                      Globalcode – Open4education
Web 2.0
 AJAX-oriented web applications;




                                   Globalcode – Open4education
Web UI Strategies
 Tip: Use the view and conversation scopes;
   Avoid to use the session scope for objects with short
   lifetime;
   Usually the lifetime is managed by the container through
   settings (Annotations or XML);




                                            Globalcode – Open4education
Web UI Strategies
 Tip: Store the persistence context into the view
 scope or conversation scope;
   The EntityManager remains open for a specified time;




                                          Globalcode – Open4education
Web UI Strategies
 Tip: Store the persistence context into the view
 scope or conversation scope;
   The EntityManager remains open for a specified time;
   Enables the 1st level cache;
   Prevents the LazyInitializationException errors;
   Enables paging in the presentation tier Integrated with
   the persistence tier;
   Attention: The 1st level cache can increase for a long
   term conversation scope.



                                             Globalcode – Open4education
Web UI Strategies
 Tip: Integrate the View Helper (pattern) with the
 persistence service (JPA);
   Implement a List (from Collections API) that receives a
   Query object (from JPA);
   Implement a DataModel (from JSF API) that receives a
   Query object;
   Implement an ExtendedTableDataModel (from
   Richfaces API) that receives an EntityManager object;
   Pagination: Use setFirtResult() and setMaxResults().
   Be careful with eager fetching!
   Filter and order by: Use CriteriaBuilder object (from
   JPA).

                                           Globalcode – Open4education
Web UI Strategies
 Tip: Use UI Components that supports “lazy
 loading” via Ajax;




                                   Globalcode – Open4education
Web UI Strategies
 Tip: Use UI Components that supports “lazy
 loading” via Ajax;




                                   Globalcode – Open4education
Web UI Strategies
 Tip: Use UI Components that supports “lazy
 loading” via Ajax;




                                   Globalcode – Open4education
Sample Application
 The tips and tricks are demonstrated by a sample
 application;
 It is avaliable to donwload at:
 http://sourceforge.net/projects/j1catalogproto2/




                                    Globalcode – Open4education
Thank you!

Alberto Lemos (Dr. Spock)       Danival Taffarel Calegari
http://www.globalcode.com.br/   http://www.matera.com/
spock@globalcode.com.br         danival@globalcode.com.br
http://twitter.com/drspockbr    http://twitter.com/danivaltc




                                             Globalcode – Open4education

Mais conteúdo relacionado

Semelhante a Performance Tips and Tricks: Java EE, Java Persistence API and JavaServer Faces

Net Beans61 Platform
Net Beans61 PlatformNet Beans61 Platform
Net Beans61 Platformsatyajit_t
 
Tools and Recipes to Replatform Monolithic Apps to Modern Cloud Environments
Tools and Recipes to Replatform Monolithic Apps to Modern Cloud EnvironmentsTools and Recipes to Replatform Monolithic Apps to Modern Cloud Environments
Tools and Recipes to Replatform Monolithic Apps to Modern Cloud EnvironmentsVMware Tanzu
 
GraphQL Advanced
GraphQL AdvancedGraphQL Advanced
GraphQL AdvancedLeanIX GmbH
 
Modern web application development with java ee 7
Modern web application development with java ee 7Modern web application development with java ee 7
Modern web application development with java ee 7Shekhar Gulati
 
JDK 8 and JDK 8 Updates in OpenJDK
JDK 8 and JDK 8 Updates in OpenJDKJDK 8 and JDK 8 Updates in OpenJDK
JDK 8 and JDK 8 Updates in OpenJDKWolfgang Weigend
 
KiranGara_JEE_7Yrs
KiranGara_JEE_7YrsKiranGara_JEE_7Yrs
KiranGara_JEE_7YrsKiran Gara
 
Opendaylight SDN Controller
Opendaylight SDN ControllerOpendaylight SDN Controller
Opendaylight SDN ControllerSumit Arora
 
Enhancing Website and Application Testing with Java Scrapers.pdf
Enhancing Website and Application Testing with Java Scrapers.pdfEnhancing Website and Application Testing with Java Scrapers.pdf
Enhancing Website and Application Testing with Java Scrapers.pdfAnanthReddy38
 
Building and managing applications fast for IBM i
Building and managing applications fast for IBM iBuilding and managing applications fast for IBM i
Building and managing applications fast for IBM iZend by Rogue Wave Software
 
[ENGLISH] TDC 2015 - PHP Trail - Tests and PHP Continuous Integration Enviro...
[ENGLISH] TDC 2015 - PHP  Trail - Tests and PHP Continuous Integration Enviro...[ENGLISH] TDC 2015 - PHP  Trail - Tests and PHP Continuous Integration Enviro...
[ENGLISH] TDC 2015 - PHP Trail - Tests and PHP Continuous Integration Enviro...Bruno Tanoue
 
Bala Sr Java Developer
Bala  Sr Java DeveloperBala  Sr Java Developer
Bala Sr Java DeveloperJava Dev
 
Getting Started with Selenium
Getting Started with SeleniumGetting Started with Selenium
Getting Started with SeleniumDave Haeffner
 
A Tool for Optimizing Java 8 Stream Software via Automated Refactoring
A Tool for Optimizing Java 8 Stream Software via Automated RefactoringA Tool for Optimizing Java 8 Stream Software via Automated Refactoring
A Tool for Optimizing Java 8 Stream Software via Automated RefactoringRaffi Khatchadourian
 
eXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework IntroductioneXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework Introductionvstorm83
 

Semelhante a Performance Tips and Tricks: Java EE, Java Persistence API and JavaServer Faces (20)

Net Beans61 Platform
Net Beans61 PlatformNet Beans61 Platform
Net Beans61 Platform
 
Tools and Recipes to Replatform Monolithic Apps to Modern Cloud Environments
Tools and Recipes to Replatform Monolithic Apps to Modern Cloud EnvironmentsTools and Recipes to Replatform Monolithic Apps to Modern Cloud Environments
Tools and Recipes to Replatform Monolithic Apps to Modern Cloud Environments
 
GraphQL Advanced
GraphQL AdvancedGraphQL Advanced
GraphQL Advanced
 
Modern web application development with java ee 7
Modern web application development with java ee 7Modern web application development with java ee 7
Modern web application development with java ee 7
 
sample1
sample1sample1
sample1
 
JDK 8 and JDK 8 Updates in OpenJDK
JDK 8 and JDK 8 Updates in OpenJDKJDK 8 and JDK 8 Updates in OpenJDK
JDK 8 and JDK 8 Updates in OpenJDK
 
KiranGara_JEE_7Yrs
KiranGara_JEE_7YrsKiranGara_JEE_7Yrs
KiranGara_JEE_7Yrs
 
Resume
ResumeResume
Resume
 
Rishabha singhcv
Rishabha singhcvRishabha singhcv
Rishabha singhcv
 
Opendaylight SDN Controller
Opendaylight SDN ControllerOpendaylight SDN Controller
Opendaylight SDN Controller
 
Enhancing Website and Application Testing with Java Scrapers.pdf
Enhancing Website and Application Testing with Java Scrapers.pdfEnhancing Website and Application Testing with Java Scrapers.pdf
Enhancing Website and Application Testing with Java Scrapers.pdf
 
Building and managing applications fast for IBM i
Building and managing applications fast for IBM iBuilding and managing applications fast for IBM i
Building and managing applications fast for IBM i
 
Cakephp manual-11
Cakephp manual-11Cakephp manual-11
Cakephp manual-11
 
[ENGLISH] TDC 2015 - PHP Trail - Tests and PHP Continuous Integration Enviro...
[ENGLISH] TDC 2015 - PHP  Trail - Tests and PHP Continuous Integration Enviro...[ENGLISH] TDC 2015 - PHP  Trail - Tests and PHP Continuous Integration Enviro...
[ENGLISH] TDC 2015 - PHP Trail - Tests and PHP Continuous Integration Enviro...
 
Bala Sr Java Developer
Bala  Sr Java DeveloperBala  Sr Java Developer
Bala Sr Java Developer
 
Vue.js Use Cases
Vue.js Use CasesVue.js Use Cases
Vue.js Use Cases
 
Getting Started with Selenium
Getting Started with SeleniumGetting Started with Selenium
Getting Started with Selenium
 
A Tool for Optimizing Java 8 Stream Software via Automated Refactoring
A Tool for Optimizing Java 8 Stream Software via Automated RefactoringA Tool for Optimizing Java 8 Stream Software via Automated Refactoring
A Tool for Optimizing Java 8 Stream Software via Automated Refactoring
 
Krishnagopal Thogiti_Java
Krishnagopal Thogiti_JavaKrishnagopal Thogiti_Java
Krishnagopal Thogiti_Java
 
eXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework IntroductioneXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework Introduction
 

Mais de Dr. Spock

Improving Batch-Process Testing Techniques with a Domain-Specific Language
Improving Batch-Process Testing Techniques with a Domain-Specific LanguageImproving Batch-Process Testing Techniques with a Domain-Specific Language
Improving Batch-Process Testing Techniques with a Domain-Specific LanguageDr. Spock
 
Avoiding Java EE Application Design Traps to Achieve Effective Use of Cloud C...
Avoiding Java EE Application Design Traps to Achieve Effective Use of Cloud C...Avoiding Java EE Application Design Traps to Achieve Effective Use of Cloud C...
Avoiding Java EE Application Design Traps to Achieve Effective Use of Cloud C...Dr. Spock
 
Evitando Armadilhas no Projeto de Aplicações Java EE para uso eficaz na nuvem
Evitando Armadilhas no Projeto de Aplicações Java EE para uso eficaz na nuvemEvitando Armadilhas no Projeto de Aplicações Java EE para uso eficaz na nuvem
Evitando Armadilhas no Projeto de Aplicações Java EE para uso eficaz na nuvemDr. Spock
 
Novidades do JSF: Um tour completo no JSF 2.2
Novidades do JSF: Um tour completo no JSF 2.2Novidades do JSF: Um tour completo no JSF 2.2
Novidades do JSF: Um tour completo no JSF 2.2Dr. Spock
 
Workshop de Introdução ao ScrumToys
Workshop de Introdução ao ScrumToysWorkshop de Introdução ao ScrumToys
Workshop de Introdução ao ScrumToysDr. Spock
 
TDC2012: Usando os recursos de extensibilidade da API de CDI do Java EE 6
TDC2012: Usando os recursos de extensibilidade da API de CDI do Java EE 6TDC2012: Usando os recursos de extensibilidade da API de CDI do Java EE 6
TDC2012: Usando os recursos de extensibilidade da API de CDI do Java EE 6Dr. Spock
 
TDC2012: Explorando os conceitos básicos da API de CDI do Java EE 6
TDC2012: Explorando os conceitos básicos da API de CDI do Java EE 6TDC2012: Explorando os conceitos básicos da API de CDI do Java EE 6
TDC2012: Explorando os conceitos básicos da API de CDI do Java EE 6Dr. Spock
 
TDC2011: Spring Mobile
TDC2011: Spring MobileTDC2011: Spring Mobile
TDC2011: Spring MobileDr. Spock
 
TDC2011: Spring, uma plataforma enterprise, social, móvel e nas nuvens
TDC2011: Spring, uma plataforma enterprise, social, móvel e nas nuvensTDC2011: Spring, uma plataforma enterprise, social, móvel e nas nuvens
TDC2011: Spring, uma plataforma enterprise, social, móvel e nas nuvensDr. Spock
 
TDC2011: Arquitetura de Software Enterprise
TDC2011: Arquitetura de Software EnterpriseTDC2011: Arquitetura de Software Enterprise
TDC2011: Arquitetura de Software EnterpriseDr. Spock
 
TDC2011: Java EE 6 & Azure
TDC2011: Java EE 6 & AzureTDC2011: Java EE 6 & Azure
TDC2011: Java EE 6 & AzureDr. Spock
 
Spring Framework no desenvolvimento móvel
Spring Framework no desenvolvimento móvelSpring Framework no desenvolvimento móvel
Spring Framework no desenvolvimento móvelDr. Spock
 
Desafios no deploy de aplicações Java EE 6 no Microsoft Azure
Desafios no deploy de aplicações Java EE 6 no Microsoft AzureDesafios no deploy de aplicações Java EE 6 no Microsoft Azure
Desafios no deploy de aplicações Java EE 6 no Microsoft AzureDr. Spock
 
Dicas e truques sobre performance em JavaEE, JPA e JSF
Dicas e truques sobre performance em JavaEE, JPA e JSFDicas e truques sobre performance em JavaEE, JPA e JSF
Dicas e truques sobre performance em JavaEE, JPA e JSFDr. Spock
 
Computação Física com Arduino, Program-ME e Java
Computação Física com Arduino, Program-ME e JavaComputação Física com Arduino, Program-ME e Java
Computação Física com Arduino, Program-ME e JavaDr. Spock
 
Spring 3: Uma Plataforma além do Framework
Spring 3: Uma Plataforma além do FrameworkSpring 3: Uma Plataforma além do Framework
Spring 3: Uma Plataforma além do FrameworkDr. Spock
 
Produtividade com Spring Roo no Google App Engine
Produtividade com Spring Roo no Google App EngineProdutividade com Spring Roo no Google App Engine
Produtividade com Spring Roo no Google App EngineDr. Spock
 
Criando uma Aplicação Web com Spring Roo em 5 minutos!
Criando uma Aplicação Web com Spring Roo em 5 minutos!Criando uma Aplicação Web com Spring Roo em 5 minutos!
Criando uma Aplicação Web com Spring Roo em 5 minutos!Dr. Spock
 
Spring Framework 3: Um 'brainstorm' de novas funcionalidades
Spring Framework 3: Um 'brainstorm' de novas funcionalidadesSpring Framework 3: Um 'brainstorm' de novas funcionalidades
Spring Framework 3: Um 'brainstorm' de novas funcionalidadesDr. Spock
 
Dicas e Truques sobre Performance em Java EE, JPA e JSF
Dicas e Truques sobre Performance em Java EE, JPA e JSFDicas e Truques sobre Performance em Java EE, JPA e JSF
Dicas e Truques sobre Performance em Java EE, JPA e JSFDr. Spock
 

Mais de Dr. Spock (20)

Improving Batch-Process Testing Techniques with a Domain-Specific Language
Improving Batch-Process Testing Techniques with a Domain-Specific LanguageImproving Batch-Process Testing Techniques with a Domain-Specific Language
Improving Batch-Process Testing Techniques with a Domain-Specific Language
 
Avoiding Java EE Application Design Traps to Achieve Effective Use of Cloud C...
Avoiding Java EE Application Design Traps to Achieve Effective Use of Cloud C...Avoiding Java EE Application Design Traps to Achieve Effective Use of Cloud C...
Avoiding Java EE Application Design Traps to Achieve Effective Use of Cloud C...
 
Evitando Armadilhas no Projeto de Aplicações Java EE para uso eficaz na nuvem
Evitando Armadilhas no Projeto de Aplicações Java EE para uso eficaz na nuvemEvitando Armadilhas no Projeto de Aplicações Java EE para uso eficaz na nuvem
Evitando Armadilhas no Projeto de Aplicações Java EE para uso eficaz na nuvem
 
Novidades do JSF: Um tour completo no JSF 2.2
Novidades do JSF: Um tour completo no JSF 2.2Novidades do JSF: Um tour completo no JSF 2.2
Novidades do JSF: Um tour completo no JSF 2.2
 
Workshop de Introdução ao ScrumToys
Workshop de Introdução ao ScrumToysWorkshop de Introdução ao ScrumToys
Workshop de Introdução ao ScrumToys
 
TDC2012: Usando os recursos de extensibilidade da API de CDI do Java EE 6
TDC2012: Usando os recursos de extensibilidade da API de CDI do Java EE 6TDC2012: Usando os recursos de extensibilidade da API de CDI do Java EE 6
TDC2012: Usando os recursos de extensibilidade da API de CDI do Java EE 6
 
TDC2012: Explorando os conceitos básicos da API de CDI do Java EE 6
TDC2012: Explorando os conceitos básicos da API de CDI do Java EE 6TDC2012: Explorando os conceitos básicos da API de CDI do Java EE 6
TDC2012: Explorando os conceitos básicos da API de CDI do Java EE 6
 
TDC2011: Spring Mobile
TDC2011: Spring MobileTDC2011: Spring Mobile
TDC2011: Spring Mobile
 
TDC2011: Spring, uma plataforma enterprise, social, móvel e nas nuvens
TDC2011: Spring, uma plataforma enterprise, social, móvel e nas nuvensTDC2011: Spring, uma plataforma enterprise, social, móvel e nas nuvens
TDC2011: Spring, uma plataforma enterprise, social, móvel e nas nuvens
 
TDC2011: Arquitetura de Software Enterprise
TDC2011: Arquitetura de Software EnterpriseTDC2011: Arquitetura de Software Enterprise
TDC2011: Arquitetura de Software Enterprise
 
TDC2011: Java EE 6 & Azure
TDC2011: Java EE 6 & AzureTDC2011: Java EE 6 & Azure
TDC2011: Java EE 6 & Azure
 
Spring Framework no desenvolvimento móvel
Spring Framework no desenvolvimento móvelSpring Framework no desenvolvimento móvel
Spring Framework no desenvolvimento móvel
 
Desafios no deploy de aplicações Java EE 6 no Microsoft Azure
Desafios no deploy de aplicações Java EE 6 no Microsoft AzureDesafios no deploy de aplicações Java EE 6 no Microsoft Azure
Desafios no deploy de aplicações Java EE 6 no Microsoft Azure
 
Dicas e truques sobre performance em JavaEE, JPA e JSF
Dicas e truques sobre performance em JavaEE, JPA e JSFDicas e truques sobre performance em JavaEE, JPA e JSF
Dicas e truques sobre performance em JavaEE, JPA e JSF
 
Computação Física com Arduino, Program-ME e Java
Computação Física com Arduino, Program-ME e JavaComputação Física com Arduino, Program-ME e Java
Computação Física com Arduino, Program-ME e Java
 
Spring 3: Uma Plataforma além do Framework
Spring 3: Uma Plataforma além do FrameworkSpring 3: Uma Plataforma além do Framework
Spring 3: Uma Plataforma além do Framework
 
Produtividade com Spring Roo no Google App Engine
Produtividade com Spring Roo no Google App EngineProdutividade com Spring Roo no Google App Engine
Produtividade com Spring Roo no Google App Engine
 
Criando uma Aplicação Web com Spring Roo em 5 minutos!
Criando uma Aplicação Web com Spring Roo em 5 minutos!Criando uma Aplicação Web com Spring Roo em 5 minutos!
Criando uma Aplicação Web com Spring Roo em 5 minutos!
 
Spring Framework 3: Um 'brainstorm' de novas funcionalidades
Spring Framework 3: Um 'brainstorm' de novas funcionalidadesSpring Framework 3: Um 'brainstorm' de novas funcionalidades
Spring Framework 3: Um 'brainstorm' de novas funcionalidades
 
Dicas e Truques sobre Performance em Java EE, JPA e JSF
Dicas e Truques sobre Performance em Java EE, JPA e JSFDicas e Truques sobre Performance em Java EE, JPA e JSF
Dicas e Truques sobre Performance em Java EE, JPA e JSF
 

Último

Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 

Último (20)

Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 

Performance Tips and Tricks: Java EE, Java Persistence API and JavaServer Faces

  • 1. Performance Tips and Tricks: Java EE, Java Persistence API, and JavaServer Faces Alberto Lemos (Dr. Spock) Danival Taffarel Calegari Senior Software Architect MATERA Systems Architect Globalcode Instructor Globalcode Instructor Globalcode – Open4education
  • 2. Agenda Motivation Data recovery strategies Lazy vs Eager Cache Web UI Design Strategies Conversation Scope View Helper + Persistence Service Lazy UI Components Globalcode – Open4education
  • 3. Objective “Present some tips and tricks on web application development with JSF, Ajax, and JPA” Globalcode – Open4education
  • 4. Motivation JavaServer Faces (JSF) is a paradigm change in Web development with Java EE; It establishes a model for web UI components. JSF evolved! JSF 1.x (without AJAX) => Ineffective event oriented JSF 1.x + AJAX lib => Event oriented JSF 2.x => Event oriented It's necessary to evolve the development techniques on presentation and persistence layers! Globalcode – Open4education
  • 5. Agenda Motivation Data recovery strategies Lazy vs Eager Cache Web UI Design Strategies Conversation Scope View Helper + Persistence Service Lazy UI Components Globalcode – Open4education
  • 6. Lazy vs Eager Strategies to handle the entity relationships; Lazy: it fetches data on demand; Eager: it always fetches data. Globalcode – Open4education
  • 7. Lazy vs Eager Tip: JPA allows for a change from lazy to eager using the JP-QL; select distinct c from Categoria c join fetch c.produtos It runs only one SELECT in the database; Join fetch solves the N+1 problem; Distinct should be used to avoid duplicated results; Note: this may cause problems with database pagination. Globalcode – Open4education
  • 8. Lazy vs Eager Tip: Try to paginate in database using lazy strategy; Use the setFirstResult and setMaxResults methods by Query. The JPA provider will use native database commands to limit the query results; Beware: join fetch for 1:N relationships causes performance and memory problems. WARN: firstResult/maxResults specified with collection fetch; applying in memory! Globalcode – Open4education
  • 9. Lazy vs Eager Tip: Try to use eager whenever bulk processing data; One common situation is report generation. Be careful with memory use; Do a previous query to get the ids and limit the results with an in clause; Use the clear method from EntityManager to remove processed objects from memory. Globalcode – Open4education
  • 10. Cache First level cache While the EntityManager is open, it maitains the references for all objects loaded by it; This cache is erased when the clear method is called. Second level cache Maintains object references per EntityManagerFactory; It is a per-application cache. Globalcode – Open4education
  • 11. Cache Globalcode – Open4education
  • 12. Cache Trick: By loading related entities into first level cache before the main query, performance will be greatly improved. It can only work with N:1 relationships for entities with a small number of instances. Example: Fetching products with any filter. If there are 200 categories, the lazy strategy should run 200 queries on the category table; Execute a “select c from Category c” before querying for products. Globalcode – Open4education
  • 13. Cache Tip: Use second level cache to save memory and to improve performance; Choose non-frequent altered entities; If an external application changes the database, data in the second level cache will become outdated. Apply a time limit for data expiration. Globalcode – Open4education
  • 14. Agenda Motivation Data recovery strategies Lazy vs Eager Cache Web UI Design Strategies Conversation Scope View Helper + Persistence Service Lazy UI Components Globalcode – Open4education
  • 15. The Problem DAO + JDBC => open/close connection; DAO + Persistence Context => open/close session; LazyInitializationException! Globalcode – Open4education
  • 16. Old Solution OpenSessionInViewFilter Design Pattern; New problems! Globalcode – Open4education
  • 17. New Problems OpenSessionInViewFilter Design Pattern; 1st REQUEST 2nd REQUEST Nth REQUEST Each request uses a different persistence context; Session scoped entities can throw LazyInitializationException! Globalcode – Open4education
  • 18. Web 1.0 Request-oriented web applications; Globalcode – Open4education
  • 19. Web 2.0 AJAX-oriented web applications; Globalcode – Open4education
  • 20. Web UI Strategies Tip: Use the view and conversation scopes; Avoid to use the session scope for objects with short lifetime; Usually the lifetime is managed by the container through settings (Annotations or XML); Globalcode – Open4education
  • 21. Web UI Strategies Tip: Store the persistence context into the view scope or conversation scope; The EntityManager remains open for a specified time; Globalcode – Open4education
  • 22. Web UI Strategies Tip: Store the persistence context into the view scope or conversation scope; The EntityManager remains open for a specified time; Enables the 1st level cache; Prevents the LazyInitializationException errors; Enables paging in the presentation tier Integrated with the persistence tier; Attention: The 1st level cache can increase for a long term conversation scope. Globalcode – Open4education
  • 23. Web UI Strategies Tip: Integrate the View Helper (pattern) with the persistence service (JPA); Implement a List (from Collections API) that receives a Query object (from JPA); Implement a DataModel (from JSF API) that receives a Query object; Implement an ExtendedTableDataModel (from Richfaces API) that receives an EntityManager object; Pagination: Use setFirtResult() and setMaxResults(). Be careful with eager fetching! Filter and order by: Use CriteriaBuilder object (from JPA). Globalcode – Open4education
  • 24. Web UI Strategies Tip: Use UI Components that supports “lazy loading” via Ajax; Globalcode – Open4education
  • 25. Web UI Strategies Tip: Use UI Components that supports “lazy loading” via Ajax; Globalcode – Open4education
  • 26. Web UI Strategies Tip: Use UI Components that supports “lazy loading” via Ajax; Globalcode – Open4education
  • 27. Sample Application The tips and tricks are demonstrated by a sample application; It is avaliable to donwload at: http://sourceforge.net/projects/j1catalogproto2/ Globalcode – Open4education
  • 28. Thank you! Alberto Lemos (Dr. Spock) Danival Taffarel Calegari http://www.globalcode.com.br/ http://www.matera.com/ spock@globalcode.com.br danival@globalcode.com.br http://twitter.com/drspockbr http://twitter.com/danivaltc Globalcode – Open4education