private static class ThreadLocalConnection extends ThreadLocal<Connection> {
public static Collection<Connection> allConnections = new LinkedList<>();
@Override
protected Connection initialValue() {
try {
Class.forName(props.getProperty("driver")); // touch the mysql driver
} catch (ClassNotFoundException e) {
log.error("ERROR", e);
}
try {
Connection con = DriverManager.getConnection(props.getProperty("url"), props.getProperty("usuario"), props.getProperty("senha"));
allConnections.add(con);
return con;
} catch (SQLException e) {
log.error("ERROR", e);
return null;
}
}
}
}