[jboss-svn-commits] JBL Code SVN: r28953 - labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Aug 16 19:28:54 EDT 2009
Author: michael.neale at jboss.com
Date: 2009-08-16 19:28:53 -0400 (Sun, 16 Aug 2009)
New Revision: 28953
Modified:
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/Backchannel.java
Log:
has a general flush to make sure no long term hanging request threads are used up... (found out after accidentaly weekend soak test)
Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/Backchannel.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/Backchannel.java 2009-08-16 18:20:42 UTC (rev 28952)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/Backchannel.java 2009-08-16 23:28:53 UTC (rev 28953)
@@ -8,6 +8,8 @@
import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
+import java.util.Timer;
+import java.util.TimerTask;
import java.util.concurrent.CountDownLatch;
/**
@@ -16,10 +18,26 @@
* @author Michael Neale
*/
public class Backchannel {
-
final List<CountDownLatch> waiting = Collections.synchronizedList(new ArrayList<CountDownLatch>());
final Map<String, List<PushResponse>> mailbox = Collections.synchronizedMap(new HashMap<String, List<PushResponse>>());
+
+ private Timer timer;
+
+ public Backchannel() {
+
+ //using a timer to make sure awaiting subs are flushed every now and then, otherwise web threads could be consumed.
+ timer = new Timer(true);
+ timer.schedule(new TimerTask() {
+ public void run() {
+ unlatchAllWaiting();
+ }
+ }, 20000, 30000);
+ }
+
+
+
+
public List<PushResponse> await(String userName) throws InterruptedException {
List<PushResponse> messages = mailbox.remove(userName);
if (messages != null && messages.size() > 0) {
@@ -51,6 +69,11 @@
resp.add(message);
}
+ unlatchAllWaiting();
+
+ }
+
+ private void unlatchAllWaiting() {
synchronized (waiting) {
Iterator<CountDownLatch> it = waiting.iterator();
while (it.hasNext()) {
@@ -59,10 +82,7 @@
it.remove();
}
}
-
}
-
-
}
More information about the jboss-svn-commits
mailing list