Link to home
Start Free TrialLog in
Avatar of bilgehanyildirim
bilgehanyildirim

asked on

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

I have a hectic app which create around 10 threads and each thread queries mysql db everysecond. (this is a stand alone java app)
I use snaq connection pool for mysql pooling
After running the app for 15 - 20 mintues, I get the following exception

... to be continued
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
 
Last packet sent to the server was 1 ms ago.
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
        at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3009)
        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2895)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3438)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2554)
        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1761)
        at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1912)
        at snaq.db.CachedPreparedStatement.executeQuery(CachedPreparedStatement.java:75)
        at com.xxxxxx.yyyyyy.auction.AuctionManager.getAuctionById(AuctionManager.java:34)
        at com.xxxxxx.yyyyyy.auction.AuctionManager.getActiveAuctions(AuctionManager.java:122)
        at com.xxxxxx.yyyyyy.job.ActiveAuctionsJob.run(ActiveAuctionsJob.java:27)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
        at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2455)
        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2906)
        ... 12 more

Open in new window

Avatar of bilgehanyildirim
bilgehanyildirim

ASKER

And this is my connection pool setup

public class MyConnection {
    private static MyConnection _instance;
    private static ConnectionPool pool;
    private MyConnection(){
        pool = new ConnectionPool("zzzzz",20,100,0,"jdbc:mysql://127.0.0.1:3306/xxxxx?autoReconnect=true","user","password");
        pool.init(5);
    }
    public static synchronized Connection getConnection() {
        if (_instance==null){
            _instance = new MyConnection();
        }
        Connection conn = null;
        try {
            conn = pool.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }
}

Open in new window

Avatar of Mick Barry
the server is closing the connection. check mysql server logs to see why.

MySql error log says

090324 21:34:16 [Warning] Aborted connection 2656 to db: 'xxxx' user: 'root' host: 'localhost' (Got an error reading communication packets)
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think you were right. I install apache pool and didn't recieve any exception so far. Thanks for the advice! The points are yours.
But one last simple question if you don't mind.
I am running this on the same box with mysql and lets say host name for that box is mysql.myserver.com.

if I use mysql.myserver.com instead of localhost or 127.0.0.1, does it effect the performance? I mean when it's FQDN, does linux out to the internet do the DNS and come back to the server or does it realize that the FQDN is actually it self and use localhost or 127.0.0.1?

Thanks
Bill
I don't *think* theres a performance issue, you could ask in the networking or unix ta for a more certain answer
From a security perspective though you are better to use 127.0.0.1 as then you can limit login access to just 127.0.0.1.

Thanks man. I'll do it.