V
V
Vanes Ri_Lax2015-08-20 15:08:02
MySQL
Vanes Ri_Lax, 2015-08-20 15:08:02

Why does the program stop connecting to MySQL?

Hello, I wrote a simple program that opens the server socket and waits for the client to connect, after the client connects, it creates a new thread and connects to the MySQL DBMS in the new thread, fetches data and sends it to the client. Everything works ok, but for some reason, after some X time of program operation, when connecting to the MySQL server, an exception is thrown:

Aug 20, 2015 2:46:33 PM Main mysqlconnect
SEVERE: null
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:389)
        at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1038)
        at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:338)
        at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2237)
        at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2270)
        at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2069)
        at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794)
        at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:389)
        at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)
        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)
        at java.sql.DriverManager.getConnection(DriverManager.java:664)
        at java.sql.DriverManager.getConnection(DriverManager.java:247)
        at Main.mysqlconnect(Main.java:43)
        at Main.list(Main.java:126)
        at Main.run(Main.java:210)
Caused by: java.net.ConnectException: Connection timed out
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:589)
        at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:213)
        at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:297)
        ... 17 more

Exception in thread "Thread-0" java.lang.NullPointerException
        at Main.list(Main.java:128)
        at Main.run(Main.java:210)

Restarting the program or the MySQL server itself does not solve the problem. However, if you reboot the machine completely, everything starts working fine again... What could be the problem?
the back end runs on CentOS 6.5
Many thanks in advance!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question