Skip to content

Commit 8e5de43

Browse files
committed
Java-574 New SemaphoresOut constructor accepting int which caller can define number of allowed permits.
1 parent 7963728 commit 8e5de43

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/main/com/mongodb/DBPortPool.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,13 @@ public static class NoMoreConnection extends MongoInternalException {
145145

146146
public static class SemaphoresOut extends NoMoreConnection {
147147
private static final long serialVersionUID = -4415279469780082174L;
148+
private static final String message = "Concurrent requests for database connection have exceeded limit";
148149
SemaphoresOut(){
149-
super( "Out of semaphores to get db connection" );
150+
super( message );
151+
}
152+
153+
SemaphoresOut(int numPermits){
154+
super( message + " of " + numPermits);
150155
}
151156
}
152157

@@ -189,7 +194,7 @@ protected int pick( int recommended, boolean couldCreate ){
189194
public DBPort get() {
190195
DBPort port = null;
191196
if ( ! _waitingSem.tryAcquire() )
192-
throw new SemaphoresOut();
197+
throw new SemaphoresOut(_waitingSem.availablePermits() );
193198

194199
try {
195200
port = get( _options.maxWaitTime );

0 commit comments

Comments
 (0)