Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

JPA 2.1 performance tuning tips

14 354 vues

Publié le

For More information, refer to Java EE 7 performance tuning and optimization book:

The book is published by Packt Publishing:
http://www.packtpub.com/java-ee-7-performance-tuning-and-optimization/book

Publié dans : Technologie
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • Sex in your area is here: ❤❤❤ http://bit.ly/36cXjBY ❤❤❤
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • Dating direct: ❤❤❤ http://bit.ly/36cXjBY ❤❤❤
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici

JPA 2.1 performance tuning tips

  1. 1. Osama Oransa osama-oransa.blogspot.com
  2. 2.  Use the proper loading strategy from either lazy loading or eager data loading according to our data size and usage; for small data volume, eager loading always make sense.  Query results pagination is also an important JPA feature. The importance of this feature is to avoid memory issues when the returned data is huge.  The JPA provides two methods to control this pagination: setMaxResults(int maxResult) and setFirstResult(int startPosition) in the Query object.
  3. 3.  Use data chunking to return the required data only from the database side, instead of filtering in the application side using the IN keyword and adding the list of IDs to the query.  Increasing the index pre-allocation size can speed up the creation of new objects. Also try to minimize the usage of composite primary keys for different entities.
  4. 4.  Enabling entity caching is important to improve the performance.  Enable the query-level caching for better performance. One way to do that is by adding a hint to the named query as follows: ◦ hints={@QueryHint(name="eclipselink.query- results-cache", value="true")}
  5. 5.  Use batch interaction by sending a group of inserts/updates/deletes to the database in a single transaction by setting "eclipselink.jdbc.batch-writing"="JDBC" in persistence.xml, we can also specify the size of the batch using another property, "eclipselink.jdbc.batch-writing.size"="2000".  Use the read-only entities when the entities are not going to be modified, such as entities for lookup data (for example, e-mail templates). ◦ This can be done using the @ReadOnly annotation on the level of the entity.
  6. 6.  Access the JPA from stateless session beans as a façade layer to get benefits from different resource injections and EJB transactional and security handling, and encapsulate all JPA access logic.  Don’t put (or minimize) any business logic in Entity setters and getters.
  7. 7.  The shared-cache-mode element in the persistence.xml deployment descriptor. <persistence-unit name="examplePU" transaction- type="JTA"> <provider>org.eclipse.persistence.jpa.PersistenceProvid er </provider> <jta-data-source>jdbc/__default</jta-data-source> <shared-cache-mode>ENABLE_SELECTIVE</shared- cache-mode> </persistence-unit>
  8. 8.  Cache retrieval mode, set by the javax.persistence.retrieveMode property, controls how data is read from the cache for calls to the EntityManager.find method and from queries.  The retrieveMode property can be set to one of the constants defined by the javax.persistence.CacheRetrieveMode enum type, either USE (the default) or BYPASS. ◦ USE, data is retrieved from the second-level cache, if available. If the data is not in the cache, the persistence provider will read it from the database. ◦ BYPASS, the second-level cache is bypassed and a call to the database is made to retrieve the data.
  9. 9.  The cache store mode, set by the javax.persistence.storeMode property, controls how data is stored in the cache.  The storeMode property can be set to one of the constants defined by the javax.persistence.CacheStoreMode enumerated type, either: ◦ USE (the default) ◦ BYPASS ◦ REFRESH  Example: EntityManager em = ...; em.setProperty("javax.persistence.cache.storeMode", "BYPASS");
  10. 10.  USE the cache data is created or updated when data is read from or committed to the database. ◦ If data is already in the cache, setting the store mode to USE will not force a refresh when data is read from the database.  BYPASS, data read from or committed to the database is not inserted or updated in the cache. ◦ That is, the cache is unchanged.  REFRESH, the cache data is created or updated when data is read from or committed to the database, and a refresh is forced on data in the cache upon database reads.
  11. 11. EntityManager em = ...; Map<String, Object> props = new HashMap<String, Object>(); props.put("javax.persistence.cache.retrieveMod e", "BYPASS"); String personPK = ...; Person person = em.find(Person.class, personPK, props);
  12. 12. EntityManager em = ...; CriteriaQuery<Person> cq = ...; TypedQuery<Person> q = em.createQuery(cq); q.setHint("javax.persistence.cache.storeMode", "REFRESH");
  13. 13. EntityManager em = ...; Cache cache = em.getEntityManagerFactory().getCache(); String personPK = ...; if (cache.contains(Person.class, personPK)) { // the data is cached } else { // the data is NOT cached }
  14. 14. EntityManager em = ...; Cache cache = em.getEntityManagerFactory().getCache(); cache.evict(Person.class, personPK); cache.evictAll();
  15. 15.  Many metadata annotations in JPA have a fetch property.  This property can take on one of two values: FetchType.EAGER or FetchType.LAZY.  FetchType.EAGER means that the field is loaded by the JPA implementation before it returns the persistent object to you. ◦ Whenever you retrieve an entity from a query or from the EntityManager, you are guaranteed that all of its eager fields are populated with datastore data.  FetchType.LAZY is a hint to the JPA runtime that you want to defer loading of the field until you access it. ◦ This is called lazy loading. Lazy loading is completely transparent; ◦ When you attempt to read the field for the first time, the JPA runtime will load the value from the datastore and populate the field automatically. ◦ Lazy loading is only a hint and not a directive because some JPA implementations cannot lazy-load certain field types.
  16. 16.  With a mix of eager and lazily-loaded fields, you can ensure that commonly-used fields load efficiently, and that other state loads transparently when accessed.  Example: @OneToOne(fetch=FetchType.LAZY) private Article article;
  17. 17. To get more details about Java EE 7 performance tuning, check my book at the following URL: http://www.packtpub.com/java-ee-7-performance-tuning-and- optimization/book

×