From e14abbfb581cd4176efaee56d270238d8ab5a55b Mon Sep 17 00:00:00 2001 From: Predrag Maric Date: Mon, 23 Jul 2018 07:41:59 +0200 Subject: [PATCH] BAEL-1818 lamdba instead of loop; isEmpty() instead of == 0 (#4791) --- .../connectionpool/connectionpools/BasicConnectionPool.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/core-java/src/main/java/com/baeldung/connectionpool/connectionpools/BasicConnectionPool.java b/core-java/src/main/java/com/baeldung/connectionpool/connectionpools/BasicConnectionPool.java index 243ec88eb5..1934d0cfc2 100644 --- a/core-java/src/main/java/com/baeldung/connectionpool/connectionpools/BasicConnectionPool.java +++ b/core-java/src/main/java/com/baeldung/connectionpool/connectionpools/BasicConnectionPool.java @@ -33,7 +33,7 @@ public class BasicConnectionPool implements ConnectionPool { @Override public Connection getConnection() throws SQLException { - if (connectionPool.size() == 0) { + if (connectionPool.isEmpty()) { if (usedConnections.size() < MAX_POOL_SIZE) { connectionPool.add(createConnection(url, user, password)); } else { @@ -76,9 +76,7 @@ public class BasicConnectionPool implements ConnectionPool { } public void shutdown() throws SQLException { - for (Connection c : usedConnections) { - this.releaseConnection(c); - } + usedConnections.forEach(this::releaseConnection); for (Connection c : connectionPool) { c.close(); }