Mysql8 small connection suspension Problem and Solution

Source: Internet
Author: User
This morning, I accidentally logged on to the Project released last night and unexpectedly reported an error. However, the opportunity for learning is coming again. The problem is as follows. I searched the internet and found that this is a common problem. Another domineering name is mysql8 small connection suspension. It is actually caused by Mysql connection timeout. The specific reason is My

This morning, I accidentally logged on to the Project released last night and unexpectedly reported an error. However, the opportunity for learning is coming again. The problem is as follows. I searched the internet and found that this is a common problem. Another domineering name is mysql 8 small connection. It is actually caused by Mysql connection timeout. The specific reason is My

This morning, I accidentally logged on to the Project released last night and unexpectedly reported an error. However, the opportunity for learning is coming again. The problem is as follows.

I searched the internet and found that this is a common problem. Another domineering name is mysql 8 small connection. It is actually caused by Mysql connection timeout. The specific reason is that the default "wait_timeout" of the Mysql server is 8 hours [that is, the default value is 28800 seconds], that is, a connection is idle for more than 8 hours, mysql will automatically disconnect the connection. In other words, if a connection is not active within 8 hours, the connection will be automatically disconnected. The value of wait timeout can be set, but it can only be 2147483 at most and cannot be larger. That is, about 24.85 days

There are two or three solutions. The most effective method is to establish a connection pool. The connection will be regularly maintained and automatically closed. If the other methods are not ideal, no explanation or record will be made.

I used hibernate in my project, but the connection pool that comes with hibernate is too scum (I heard that there is no research, but this problem can be seen from one hand that it is not powerful ). Therefore, you can only use mainstream connection pools.

1. DBCP.

Apche's DBCP is supported in Hibernate2, but it is no longer recommended in Hibernate3. The official explanation is that this connection pool has defects. If you need to use DBCP in Hibernate3 for some reason, we recommend that you use the JNDI method.

2. C3P0.

The namespaces of Hibernate2 and Hibernate3 have changed. For example, when C3P0 is configured, provider_class uses net. sf. hibernate. connection. C3P0ConnectionProvider in Hibernate2 and org. hibernate. connection. C3P0ConnectionProvider in Hibernate3.

3. Proxool

As for the comparison between the three, there are a lot of people on the Internet to search for, I found a more interesting small experiment, you can coding to test the performance, you can try.

Interesting experiments also added a comparison with druid (http://286.iteye.com/blog/1920417)

In my project, I chose c3p0. The configuration process is listed as follows:

Hibernate. cfg. xml


  
   
    
     
Org. hibernate. connection. C3P0ConnectionProvider
             
                
    
     
5
              
                
    
     
30
              
              
    
     
1800
              
                
    
     
100
              
                
    
     
121
              
                
    
     
3
              
    
     
True
    
    
    
     
60
    
    
     
True
    
    
     
Org. hibernate. dialect. MySQLDialect
    
    
     
Jdbc: mysql: // xxxx: 3306/xxx? UseUnicode = true & characterEncoding = UTF8
    
    
     
Username
    
    
     
Password
    
    
     
Com. mysql. jdbc. Driver
    
    
    
   
  

A good hibernate configuration c3p0 Tutorial: http://www.cnblogs.com/best/archive/2013/05/09/3069839.html

Many tutorials on the Internet mean that the following statements must be added. In fact, I have no errors here, mainly in the cited package.


  
   org.hibernate.connection.C3P0ConnectionProvider
   

The c3p0-0.9.2.1.jar is started to import, but there is always a problem, cocould not initialize class com. dao. HibernateSessionFactory. Finally, import the following two jar packages to solve the problem. c3p0 is successfully configured.

C3p0-0.9.1.jar and hibernate-c3p0-4.1.11.Final.jar (I have uploaded resources)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.