File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed
src/main/java/org/javawebstack/orm/connection/pool Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ public class PooledSQL implements SQL, AutoCloseable {
1616 private boolean closed ;
1717
1818 public PooledSQL (SQLPool pool , SQL connection ) {
19+ if (connection == null )
20+ throw new IllegalArgumentException ("connection can not be null" );
1921 this .pool = pool ;
2022 this .connection = connection ;
2123 }
Original file line number Diff line number Diff line change 44import org .javawebstack .orm .connection .SQL ;
55
66import java .util .*;
7+ import java .util .concurrent .BlockingQueue ;
78import java .util .concurrent .LinkedBlockingQueue ;
89import java .util .function .Supplier ;
910
@@ -12,7 +13,7 @@ public class SQLPool {
1213 private final PoolScaling scaling ;
1314 private final Supplier <SQL > supplier ;
1415 private final List <SQL > connections = new ArrayList <>();
15- private final Queue <SQL > connectionQueue = new LinkedBlockingQueue <>();
16+ private final BlockingQueue <SQL > connectionQueue = new LinkedBlockingQueue <>();
1617 private final Set <QueryLogger > loggers = new HashSet <>();
1718 private boolean closing ;
1819 private PoolQueryLogger queryLogger = new PoolQueryLogger ();
@@ -31,9 +32,13 @@ public PooledSQL get() {
3132 if (closing )
3233 throw new IllegalStateException ("Pool has already been closed" );
3334 scale ();
34- SQL sql = connectionQueue .poll ();
35- scale ();
36- return new PooledSQL (this , sql );
35+ try {
36+ SQL sql = connectionQueue .take ();
37+ scale ();
38+ return new PooledSQL (this , sql );
39+ } catch (InterruptedException e ) {
40+ throw new RuntimeException (e );
41+ }
3742 }
3843
3944 public void release (SQL sql ) {
You can’t perform that action at this time.
0 commit comments