I am writing a game server that requires connecting to a MySQL database server to retrieve information about players or certain items in the game (the latter is only taken at server start). Should I have one connection to the database constantly open, and then check it for having failed / broken before use, or make a single connection for every request.
The current system (new connection for every player join), is adding noticeable latency to the login process.
Is it possible to have an always open MySQL connection in Java?
Have a look at the
ConnectionPoolclasses of Java to have a set of persistent connections open. See here for an article on MySql connection pooling with Java. For some existing implementations you might refer to this question: Java JDBC connection pool library choice in 2011/2012?That way you save the overhead of opening a connection over and over again, but have the amount of connections you need available, when you need them.