Skip to content

Commit 26d84e4

Browse files
committed
Added fix for race condition
1 parent 7787b9e commit 26d84e4

File tree

1 file changed

+12
-10
lines changed
  • src/main/java/org/javawebstack/orm/connection/pool

1 file changed

+12
-10
lines changed

src/main/java/org/javawebstack/orm/connection/pool/SQLPool.java

+12-10
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,18 @@ public void scale() {
6868
int newScale = scaling.scale(connections.size(), connections.size() - connectionQueue.size());
6969
if(newScale == connections.size())
7070
return;
71-
while (newScale > connections.size()) {
72-
SQL sql = supplier.get();
73-
sql.addQueryLogger(queryLogger);
74-
connections.add(sql);
75-
connectionQueue.add(sql);
76-
}
77-
while (newScale < connections.size() && connectionQueue.size() > 0) {
78-
SQL sql = connectionQueue.poll();
79-
sql.close();
80-
connections.remove(sql);
71+
synchronized (this) {
72+
while (newScale > connections.size()) {
73+
SQL sql = supplier.get();
74+
sql.addQueryLogger(queryLogger);
75+
connections.add(sql);
76+
connectionQueue.add(sql);
77+
}
78+
while (newScale < connections.size() && !connectionQueue.isEmpty()) {
79+
SQL sql = connectionQueue.poll();
80+
sql.close();
81+
connections.remove(sql);
82+
}
8183
}
8284
}
8385

0 commit comments

Comments
 (0)