I cache database connection objects via WeakHashMap as like:
Connection conn;
if (connectionCache.get(jdbc.getConnectionURL()) == null) {
conn = DriverManager.getConnection(jdbc.getConnectionURL(), jdbc.getUsername(), jdbc.getPassword());
connectionCache.put(jdbc.getConnectionURL(), conn);
} else {
conn = connectionCache.get(jdbc.getConnectionURL());
}
Is it possible:
If statement is checked and seen that there is already an object at cache and before running else statement cache is invalidated?