I have this singelton with Connection Pool.
public enum ConnectionPool {
INSTANCE;
private DataSource ds = null;
ConnectionPool() {
try {
final Context initCtx = new InitialContext();
ds = (DataSource) initCtx.lookup("java:comp/env/jdbc/test");
} catch (NamingException e) {
e.printStackTrace();
}
}
public Connection getConnection() throws SQLException {
return ds.getConnection();
}
}
Should I synchronize getConnection() in order to prevent getting the same instance from different threads? It looks like it has been already synchronized by Tomcat but I'm not sure(I use Tomcat 8).