File tree 2 files changed +11
-4
lines changed
src/main/java/org/javawebstack/orm/connection/pool
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 {
16
16
private boolean closed ;
17
17
18
18
public PooledSQL (SQLPool pool , SQL connection ) {
19
+ if (connection == null )
20
+ throw new IllegalArgumentException ("connection can not be null" );
19
21
this .pool = pool ;
20
22
this .connection = connection ;
21
23
}
Original file line number Diff line number Diff line change 4
4
import org .javawebstack .orm .connection .SQL ;
5
5
6
6
import java .util .*;
7
+ import java .util .concurrent .BlockingQueue ;
7
8
import java .util .concurrent .LinkedBlockingQueue ;
8
9
import java .util .function .Supplier ;
9
10
@@ -12,7 +13,7 @@ public class SQLPool {
12
13
private final PoolScaling scaling ;
13
14
private final Supplier <SQL > supplier ;
14
15
private final List <SQL > connections = new ArrayList <>();
15
- private final Queue <SQL > connectionQueue = new LinkedBlockingQueue <>();
16
+ private final BlockingQueue <SQL > connectionQueue = new LinkedBlockingQueue <>();
16
17
private final Set <QueryLogger > loggers = new HashSet <>();
17
18
private boolean closing ;
18
19
private PoolQueryLogger queryLogger = new PoolQueryLogger ();
@@ -31,9 +32,13 @@ public PooledSQL get() {
31
32
if (closing )
32
33
throw new IllegalStateException ("Pool has already been closed" );
33
34
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
+ }
37
42
}
38
43
39
44
public void release (SQL sql ) {
You can’t perform that action at this time.
0 commit comments