You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by pa...@apache.org on 2011/09/17 09:02:31 UTC
svn commit: r1171921 -
/incubator/airavata/trunk/modules/ws-messenger/commons/src/main/java/org/apache/airavata/wsmg/commons/storage/ConnectionPool.java
Author: patanachai
Date: Sat Sep 17 07:02:30 2011
New Revision: 1171921
URL: http://svn.apache.org/viewvc?rev=1171921&view=rev
Log:
AIRAVATA-101 fix synchronization problem by using AtomicInteger instead of Integer Object
Modified:
incubator/airavata/trunk/modules/ws-messenger/commons/src/main/java/org/apache/airavata/wsmg/commons/storage/ConnectionPool.java
Modified: incubator/airavata/trunk/modules/ws-messenger/commons/src/main/java/org/apache/airavata/wsmg/commons/storage/ConnectionPool.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/ws-messenger/commons/src/main/java/org/apache/airavata/wsmg/commons/storage/ConnectionPool.java?rev=1171921&r1=1171920&r2=1171921&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/ws-messenger/commons/src/main/java/org/apache/airavata/wsmg/commons/storage/ConnectionPool.java (original)
+++ incubator/airavata/trunk/modules/ws-messenger/commons/src/main/java/org/apache/airavata/wsmg/commons/storage/ConnectionPool.java Sat Sep 17 07:02:30 2011
@@ -27,6 +27,7 @@ import java.sql.SQLException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Stack;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.sql.DataSource;
@@ -52,7 +53,7 @@ public class ConnectionPool {
private boolean autoCommit = true;
private boolean waitIfBusy;
- private Integer needConnection = 0;
+ private AtomicInteger needConnection = new AtomicInteger(0);
private boolean stop;
private Stack<Connection> availableConnections;
@@ -152,7 +153,7 @@ public class ConnectionPool {
} else {
// request connection creation and then wait
synchronized (needConnection) {
- needConnection++;
+ needConnection.incrementAndGet();
needConnection.notifyAll();
}
@@ -193,11 +194,11 @@ public class ConnectionPool {
private synchronized void fillUpConnection() throws SQLException {
synchronized (needConnection) {
- if (needConnection > 0) {
+ if (needConnection.get() > 0) {
Connection connection = makeNewConnection();
availableConnections.push(connection);
setTimeStamp(connection);
- needConnection--;
+ needConnection.decrementAndGet();
}
}
}