Data source rejected establishment of connection, message from server: & quot; Too connector connections & quot;, establishment

Source: Internet
Author: User

Data source rejected establishment of connection, message from server: "Too many connections", establishment
Detailed error message:

Severe: StandardWrapper. Throwable
Org. springframework. transaction. CannotCreateTransactionException: cocould not open JDBC Connection for transaction; nested exception is org. apache. commons. dbcp. SQLNestedException: Error preloading the connection pool
At org. springframework. jdbc. datasource. DataSourceTransactionManager. doBegin (DataSourceTransactionManager. java: 241)
At org. springframework. transaction. support. AbstractPlatformTransactionManager. getTransaction (AbstractPlatformTransactionManager. java: 372)
At org. springframework. transaction. interceptor. TransactionAspectSupport. createTransactionIfNecessary (TransactionAspectSupport. java: 417)
At org. springframework. transaction. interceptor. TransactionAspectSupport. invokeWithinTransaction (TransactionAspectSupport. java: 255)
At org. springframework. transaction. interceptor. TransactionInterceptor. invoke (TransactionInterceptor. java: 94)
At org. springframework. aop. framework. ReflectiveMethodInvocation. proceed (ReflectiveMethodInvocation. java: 172)
At org. springframework. aop. framework. CglibAopProxy $ DynamicAdvisedInterceptor. intercept (CglibAopProxy. java: 633)
At com. qujiu. base. service. XgPlatformManager $ EnhancerBySpringCGLIB $ define e244c. getPlarMark (<generated>)
At com. qujiu. base. web. init. BaseDataDictionary. init (BaseDataDictionary. java: 40)
At org. apache. catalina. core. StandardWrapper. initServlet (StandardWrapper. java: 1284)
At org. apache. catalina. core. StandardWrapper. loadServlet (StandardWrapper. java: 1197)
At org. apache. catalina. core. StandardWrapper. load (StandardWrapper. java: 1087)
At org. apache. catalina. core. StandardContext. loadOnStartup (StandardContext. java: 5210)
At org. apache. catalina. core. StandardContext. startInternal (StandardContext. java: 5493)
At org. apache. catalina. util. LifecycleBase. start (LifecycleBase. java: 150)
At org. apache. catalina. core. ContainerBase $ StartChild. call (ContainerBase. java: 1559)
At org. apache. catalina. core. ContainerBase $ StartChild. call (ContainerBase. java: 1549)
At java. util. concurrent. FutureTask. run (FutureTask. java: 262)
At java. util. concurrent. ThreadPoolExecutor. runWorker (ThreadPoolExecutor. java: 1145)
At java. util. concurrent. ThreadPoolExecutor $ Worker. run (ThreadPoolExecutor. java: 615)
At java. lang. Thread. run (Thread. java: 745)
Caused by: org. apache. commons. dbcp. SQLNestedException: Error preloading the connection pool
At org. apache. commons. dbcp. BasicDataSource. createDataSource (BasicDataSource. java: 868)
At org. apache. commons. dbcp. BasicDataSource. getConnection (BasicDataSource. java: 540)
At org. springframework. jdbc. datasource. DataSourceTransactionManager. doBegin (DataSourceTransactionManager. java: 203)
... 20 more
Caused by: com. mysql. jdbc. exceptions. jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too many ons"
At sun. reflect. NativeConstructorAccessorImpl. newInstance0 (Native Method)
At sun. reflect. nativeconstruct%cessorimpl. newInstance (nativeconstruct%cessorimpl. java: 57)
At sun. reflect. delegatingconstruct%cessorimpl. newInstance (delegatingconstruct%cessorimpl. java: 45)
At java. lang. reflect. Constructor. newInstance (Constructor. java: 526)
At com. mysql. jdbc. Util. handleNewInstance (Util. java: 411)
At com. mysql. jdbc. Util. getInstance (Util. java: 386)
At com. mysql. jdbc. SQLError. createSQLException (SQLError. java: 1014)
At com. mysql. jdbc. SQLError. createSQLException (SQLError. java: 988)
At com. mysql. jdbc. SQLError. createSQLException (SQLError. java: 974)
At com. mysql. jdbc. MysqlIO. doHandshake (MysqlIO. java: 1104)
At com. mysql. jdbc. ConnectionImpl. coreConnect (ConnectionImpl. java: 2412)
At com. mysql. jdbc. ConnectionImpl. connectOneTryOnly (ConnectionImpl. java: 2445)
At com. mysql. jdbc. ConnectionImpl. createNewIO (ConnectionImpl. java: 2230)
At com. mysql. jdbc. ConnectionImpl. <init> (ConnectionImpl. java: 813)
At com. mysql. jdbc. JDBC4Connection. <init> (JDBC4Connection. java: 47)
At sun. reflect. NativeConstructorAccessorImpl. newInstance0 (Native Method)
At sun. reflect. nativeconstruct%cessorimpl. newInstance (nativeconstruct%cessorimpl. java: 57)
At sun. reflect. delegatingconstruct%cessorimpl. newInstance (delegatingconstruct%cessorimpl. java: 45)
At java. lang. reflect. Constructor. newInstance (Constructor. java: 526)
At com. mysql. jdbc. Util. handleNewInstance (Util. java: 411)
At com. mysql. jdbc. ConnectionImpl. getInstance (ConnectionImpl. java: 399)
At com. mysql. jdbc. NonRegisteringDriver. connect (NonRegisteringDriver. java: 334)
At org. apache. commons. dbcp. DriverConnectionFactory. createConnection (DriverConnectionFactory. java: 37)
At org. apache. commons. dbcp. PoolableConnectionFactory. makeObject (PoolableConnectionFactory. java: 290)
At org. apache. commons. pool. impl. GenericObjectPool. addObject (GenericObjectPool. java: 996)
At org. apache. commons. dbcp. BasicDataSource. createDataSource (BasicDataSource. java: 865)
... 22 more


July 30 12:04:20 org. apache. catalina. core. StandardContext loadOnStartup
Severe: Servlet/wowo-web threw load () exception
Com. mysql. jdbc. exceptions. jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too has connections"
At sun. reflect. NativeConstructorAccessorImpl. newInstance0 (Native Method)
At sun. reflect. nativeconstruct%cessorimpl. newInstance (nativeconstruct%cessorimpl. java: 57)
At sun. reflect. delegatingconstruct%cessorimpl. newInstance (delegatingconstruct%cessorimpl. java: 45)
At java. lang. reflect. Constructor. newInstance (Constructor. java: 526)
At com. mysql. jdbc. Util. handleNewInstance (Util. java: 411)
At com. mysql. jdbc. Util. getInstance (Util. java: 386)
At com. mysql. jdbc. SQLError. createSQLException (SQLError. java: 1014)
At com. mysql. jdbc. SQLError. createSQLException (SQLError. java: 988)
At com. mysql. jdbc. SQLError. createSQLException (SQLError. java: 974)
At com. mysql. jdbc. MysqlIO. doHandshake (MysqlIO. java: 1104)
At com. mysql. jdbc. ConnectionImpl. coreConnect (ConnectionImpl. java: 2412)
At com. mysql. jdbc. ConnectionImpl. connectOneTryOnly (ConnectionImpl. java: 2445)
At com. mysql. jdbc. ConnectionImpl. createNewIO (ConnectionImpl. java: 2230)
At com. mysql. jdbc. ConnectionImpl. <init> (ConnectionImpl. java: 813)
At com. mysql. jdbc. JDBC4Connection. <init> (JDBC4Connection. java: 47)
At sun. reflect. NativeConstructorAccessorImpl. newInstance0 (Native Method)
At sun. reflect. nativeconstruct%cessorimpl. newInstance (nativeconstruct%cessorimpl. java: 57)
At sun. reflect. delegatingconstruct%cessorimpl. newInstance (delegatingconstruct%cessorimpl. java: 45)
At java. lang. reflect. Constructor. newInstance (Constructor. java: 526)
At com. mysql. jdbc. Util. handleNewInstance (Util. java: 411)
At com. mysql. jdbc. ConnectionImpl. getInstance (ConnectionImpl. java: 399)
At com. mysql. jdbc. NonRegisteringDriver. connect (NonRegisteringDriver. java: 334)
At org. apache. commons. dbcp. DriverConnectionFactory. createConnection (DriverConnectionFactory. java: 37)
At org. apache. commons. dbcp. PoolableConnectionFactory. makeObject (PoolableConnectionFactory. java: 290)
At org. apache. commons. pool. impl. GenericObjectPool. addObject (GenericObjectPool. java: 996)
At org. apache. commons. dbcp. BasicDataSource. createDataSource (BasicDataSource. java: 865)
At org. apache. commons. dbcp. BasicDataSource. getConnection (BasicDataSource. java: 540)
At org. springframework. jdbc. datasource. DataSourceTransactionManager. doBegin (DataSourceTransactionManager. java: 203)
At org. springframework. transaction. support. AbstractPlatformTransactionManager. getTransaction (AbstractPlatformTransactionManager. java: 372)
At org. springframework. transaction. interceptor. TransactionAspectSupport. createTransactionIfNecessary (TransactionAspectSupport. java: 417)
At org. springframework. transaction. interceptor. TransactionAspectSupport. invokeWithinTransaction (TransactionAspectSupport. java: 255)
At org. springframework. transaction. interceptor. TransactionInterceptor. invoke (TransactionInterceptor. java: 94)
At org. springframework. aop. framework. ReflectiveMethodInvocation. proceed (ReflectiveMethodInvocation. java: 172)
At org. springframework. aop. framework. CglibAopProxy $ DynamicAdvisedInterceptor. intercept (CglibAopProxy. java: 633)
At com. qujiu. base. service. XgPlatformManager $ EnhancerBySpringCGLIB $ define e244c. getPlarMark (<generated>)
At com. qujiu. base. web. init. BaseDataDictionary. init (BaseDataDictionary. java: 40)
At org. apache. catalina. core. StandardWrapper. initServlet (StandardWrapper. java: 1284)
At org. apache. catalina. core. StandardWrapper. loadServlet (StandardWrapper. java: 1197)
At org. apache. catalina. core. StandardWrapper. load (StandardWrapper. java: 1087)
At org. apache. catalina. core. StandardContext. loadOnStartup (StandardContext. java: 5210)
At org. apache. catalina. core. StandardContext. startInternal (StandardContext. java: 5493)
At org. apache. catalina. util. LifecycleBase. start (LifecycleBase. java: 150)
At org. apache. catalina. core. ContainerBase $ StartChild. call (ContainerBase. java: 1559)
At org. apache. catalina. core. ContainerBase $ StartChild. call (ContainerBase. java: 1549)
At java. util. concurrent. FutureTask. run (FutureTask. java: 262)
At java. util. concurrent. ThreadPoolExecutor. runWorker (ThreadPoolExecutor. java: 1145)
At java. util. concurrent. ThreadPoolExecutor $ Worker. run (ThreadPoolExecutor. java: 615)
At java. lang. Thread. run (Thread. java: 745)

July 30 12:04:20 org. apache. catalina. core. ApplicationContext log
Information: Initializing Spring FrameworkServlet 'springmvc'
July 30 12:04:21 org. apache. coyote. AbstractProtocol start
Information: Starting ProtocolHandler ["http-bio-8080"]
July 30 12:04:21 org. apache. coyote. AbstractProtocol start
Information: Starting ProtocolHandler ["ajp-bio-8009"]
July 30 12:04:21 org. apache. catalina. startup. Catalina start
Information: Server startup in 18779 MS

Problem Analysis:

View the current maximum number of connections of MySQL. log on to MySQL: mysql-uroot-p. Press enter. Enter the password and press Enter;

Enter the command: select VARIABLE_VALUE from information_schema.GLOBAL_VARIABLES where VARIABLE_NAME = 'max _ CONNECTIONS '; press ENTER

The current maximum number of connections is 151. I used the method in "setting 1040 too connections for mysql maximum number of connections in CentOS" to set it to 3600. How can I change it to 151 now? Previously, this method only temporarily modified the maximum number of connections and restored it after the MySQL service was restarted.

Solution:

To completely solve the problem, modify my. cnf configuration file. Here we use VI to modify it. Enter the command: vi/usr/my. press enter to open the file and press "I" to enter the editing status;

Add "max_connections = 3600" under "[mysqld]", Press Esc to Enter command mode, enter ": wq" and press enter (save and exit ).

Run: service mysql restart to restart the MySQL service. It may take a long time to start the service and wait patiently ......

Note: As mentioned in many articles, adding "set-variable = max_connections = 1000" under "[mysqld]" does not work at all. The service cannot be started after it is added.

My environment is: CentOS 6.5 MySQL 5.6




How does hibernate + mysql too connector connections close the database connection?

In hibernate, we use Threadlocal to manage sessions. after close (), Threadlocal is not empty yet. If your hibernate session resources are insufficient, it is easy to generate the Too worker connections exception. You can try this solution.
1. Add a connection pool configuration file to increase the number of threads in the session thread pool.
<Property name = "hibernate. connection. provider_class">
Org. hibernate. connection. C3P0ConnectionProvider
</Property>
<Property name = "hibernate. c3p0. max_size"> 30 </property> <------ you can set a larger value.
<Property name = "hibernate. c3p0. min_size"> 1 </property>
<Property name = "hibernate. c3p0. timeout"> 1800 </property>
<Property name = "hibernate. c3p0. max_statements"> 1000 </property>
<Property name = "hibernate. c3p0. idle_test_period"> 30000 </property>
<Property name = "hibernate. c3p0. acquire_increment"> 1 </property>
<Property name = "hibernate. c3p0. validate"> false </property>
2. Use the upstairs method to change session. close () to sessionFactory. closeSession (), because when session is closed with sessionFactory, The ThreadLocal session will be cleared.
Try it. If not, it may be a session issue.
--------------------------------------------
No. Sorry, it's hibernateSessionFactory. closeSession ()
_________________________________________________ Are you often using hibernate to insert a large amount of data?
Is there an out of memory prompt?
Because hibernate uses the cache to insert data, when you save
It only saves the data in the session and does not insert it immediately. Therefore, frequent insertion of a large amount of data may result in insufficient memory.
______________________________________________-
However, there is a solution for the author... the remaining full text>

Mysql + hibernate

The main reason is that there is a certain waiting time to disconnect from MySQL and release the connection, which is caused by your continuous connection in a short time. Just like the connection in the TCP/IP protocol, after the client is disconnected, the server is not cleared immediately, but usually in the TIME_WAIT status and will be disconnected after a certain period of time.
In Hibernate, you should construct your own session factory and save your session with static methods or variables.

For example:

Import org. hibernate. HibernateException;
Import org. hibernate. Session;
Import org. hibernate. cfg. Configuration;

/**
* Configures and provides access to Hibernate sessions, tied to
* Current thread of execution. Follows the Thread Local Session
* Pattern, see {@ link hibernate.org/42.html }.
*/
Public class HibernateSessionFactory {

/**
* Location of hibernate. cfg. xml file.
* Location shoshould be on the classpath as Hibernate uses
* # ResourceAsStream style lookup for its configuration file.
* The default classpath location of the hibernate config file is
* In the default package. Use # setConfigFile () to update
* The location of the configuration file for the current session.
*/
Private static String CONFIG_FILE_LOCATION = "/com/sxws/chis/object/hibernate. cfg. xml ";
Private static final ThreadLocal <Session> threadLocal = new ThreadLocal <Session> ();
Private static Configuration configuration = new Configuration ();
Private static org. hibernate. SessionFactory sessionFactory;
Private static String configFile = CONFIG_FILE_LOCATION;

Static {
Try {
Configuration. configure (configFile );
Ses ...... the remaining full text>

Related Article

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.