Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Hibernate Performance Optimization of reusing SessionFactory     - 20 Unix / Linux command skills (Linux)

- The best tools and techniques to find data on a Unix system (Linux)

- Shell Common Command Summary (Programming)

- Linux bash: scp: command not found the problem (Linux)

- Ubuntu 12.04 install RTL8723BE wireless network card driver (Programming)

- PostgreSQL using the system cache to improve operational efficiency (Database)

- There are more than one server, there is reason to try cloud operating system (Server)

- Mac OS X system setup Google Go language development environment configuration tool Sublime Text 2 (Linux)

- PostgreSQL with the C Completing the storage process instances (Database)

- awk pattern matching (Programming)

- Linux System Getting Started Tutorial: how to find information on Linux-embedded module (Linux)

- Big Data Common Glossary (Linux)

- Firewall settings oracle remote connection in Linux systems (Linux)

- Ubuntu Linux use MAC binding against ARP attacks (Linux)

- How Mutt mail client to use cipher text password (Linux)

- Linux start the process (Linux)

- Mac OS X systems create Ubuntu USB boot disk for the Mac (Linux)

- Without Visual Studio .NET Windows application development (Programming)

- Close and limit unused ports computer server security protection (Linux)

- JavaScript subarray Deduplication (Programming)

 
         
  Hibernate Performance Optimization of reusing SessionFactory
     
  Add Date : 2018-11-21      
         
         
         
  Hibernate Optimization There are many ways, such as caching, lazy loading and reasonable with SQL mapping, by optimizing the use of SessionFactory it is the most basic.

SessionFactory instance responsible for creating Session, Session equivalent in the JDBC Connection.

SessionFactory creation

-------------------------------------------------- ------------------------------

SessionFactory is built from the Configuration, Configuration based on configuration information to build a SessionFactory.

SessionFactory saved in the database corresponding to the current configuration of all the mappings, also responsible for maintaining cache and Statement pool, so SessionFactory creation process is very time consuming.

Hibernate SessionFactory in the proposed design code reuse strategy, and SessionFactory is thread-safe by default, allows multiple threads to concurrent calls.

General system simply create a SessionFactory instance, each time to avoid re-created, it could be better shared L2 cache.

SessionFactory reuse

-------------------------------------------------- ------------------------------

NetBeans provides a default HibernateUtil.java reuse SessionFactory.

In my own project implements a reusable class that can be used as reference:


public class HibernateSessionFactory {

    private final Configuration configuration;
    private final ServiceRegistry serviceRegistry;
    private final SessionFactory sessionFactory;

    private HibernateSessionFactory () {
        configuration = new Configuration () configure ().;
        serviceRegistry = new ServiceRegistryBuilder () applySettings (configuration.getProperties ()) build ()..;
        sessionFactory = configuration.buildSessionFactory (serviceRegistry);
    }

    public Session getSession () {
        return sessionFactory.openSession ();
    }

    private static class SingletonHolder {

        private final static HibernateSessionFactory INSTANCE = new HibernateSessionFactory ();
    }

    public static HibernateSessionFactory getInstance () {
        return SingletonHolder.INSTANCE;
    }

}

 

To consider this place a multithreaded environment design, the use of inner classes to support multiple threads.

Performance Testing

-------------------------------------------------- ------------------------------

For the first reuse and reuse after ab command with a simple performance testing, performance doubled, the effect is very obvious.
     
         
         
         
  More:      
 
- RHEL5 multipath configuration (Linux)
- Use GNU / Linux broadcasting of television programs (Linux)
- Kernel compile under Debian (Linux)
- Detailed usage history command (Linux)
- Java coding conventions (Programming)
- Android 4.2 compilation notes (Programming)
- RHEL 6.5 x86_64 CentOS yum configuration source (Linux)
- Fedora 22 install Adobe Flash Player (Linux)
- MySQL DATE_FORMAT () function (Database)
- Android screen rotation processing and ProgressDialog the best AsyncTask (Programming)
- LogStash log analysis display system (Linux)
- Linux maximum number of threads and limit the number of queries the current thread (Linux)
- CentOS 6.5 / Linux restart network card being given Determining if ip address x.x.x.x is already in use (Linux)
- To install network scanning and packet sniffer tool Nmap 7.00 under ubuntu (Linux)
- Use the top command (Linux)
- How to install Ubuntu strategy game Wesnoth 1.12.0 (Linux)
- Awk include binding capacity larger than the specified size of all files directory (Linux)
- How to Install Node.js in CentOS 7 (Linux)
- STL spatial Configurator (Programming)
- Copy files between two Linux hosts (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.