User: danch
Date: 01/07/01 20:20:08
Modified: src/main/org/jboss/pool ObjectPool.java
Log:
Added timeout parameter for blocking
Revision Changes Path
1.2 +25 -2 jbosspool/src/main/org/jboss/pool/ObjectPool.java
Index: ObjectPool.java
===================================================================
RCS file: /cvsroot/jboss/jbosspool/src/main/org/jboss/pool/ObjectPool.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ObjectPool.java 2001/05/15 07:58:24 1.1
+++ ObjectPool.java 2001/07/02 03:20:08 1.2
@@ -27,6 +27,10 @@
* @see org.jboss.pool.PooledObject
*
* @author Aaron Mulder ([EMAIL PROTECTED])
+ * @author <a href="mailto:[EMAIL PROTECTED]">danch (Dan Christopherson)</a>
+ *
+ * Revision:
+ * 20010701 danch added code for timeout in blocking.
*/
public class ObjectPool implements PoolEventListener {
private final static String INITIALIZED = "Pool already initialized!";
@@ -50,6 +54,7 @@
private long gcIntervalMillis = 120000l; // shrink & gc every 2 minutes
private long lastGC = System.currentTimeMillis();
private boolean blocking = true;
+ private int blockingTimeout = -1;// meaning forever
private boolean trackLastUsed = false;
private boolean invalidateOnError = false;
private PrintWriter logWriter = null;
@@ -418,6 +423,18 @@
*/
public boolean isBlocking() {return blocking;}
+ /** sets how long to wait for a free object when blocking, -1 indicating
+ * forever.
+ */
+ public void setBlockingTimeout(int blockingTimeout) {
+ this.blockingTimeout = blockingTimeout;
+ }
+
+ /** get how long this pool will wait for a free object while blocking */
+ public int getBlockingTimeout() {
+ return this.blockingTimeout;
+ }
+
/**
* Sets whether object clients can update the last used time. If not, the
* last used time will only be updated when the object is given to a client
@@ -537,6 +554,7 @@
if(result != null) // If this is identical to a previous request,
return result; // return the same result. This is unusual.
+ boolean shouldBlock = blocking;
while(true) {
Iterator it = objects.values().iterator();
while(it.hasNext()) {
@@ -570,11 +588,16 @@
if(result != null)
return result;
- if(blocking) {
+ if(shouldBlock) {
log("Pool "+this+" waiting for a free object");
synchronized(this) {
try {
- wait();
+ if (blockingTimeout > 0) {
+ wait(blockingTimeout);
+ shouldBlock = false; //don't wait again
+ } else {
+ wait();
+ }
} catch(InterruptedException e) {}
}
} else {
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development