Author: alessio.soldano(a)jboss.com
Date: 2009-07-30 09:51:36 -0400 (Thu, 30 Jul 2009)
New Revision: 10435
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/eventing/mgmt/SubscriptionManager.java
Log:
[JBWS-2711] Make sure the WatchDog worker thread is stopped when stopping the
SubscriptionManager
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/eventing/mgmt/SubscriptionManager.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/eventing/mgmt/SubscriptionManager.java 2009-07-30
11:04:31 UTC (rev 10434)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/eventing/mgmt/SubscriptionManager.java 2009-07-30
13:51:36 UTC (rev 10435)
@@ -28,6 +28,8 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -182,22 +184,22 @@
{
// remove event dispatcher
Util.unbind(new InitialContext(), EventingConstants.DISPATCHER_JNDI_NAME);
-
- // stop thread pool
- threadPool.shutdown();
-
- // stop the watchdog
- watchDog.shutdown();
-
- for (URI eventSourceNS : eventSourceMapping.keySet())
- {
- removeEventSource(eventSourceNS);
- }
}
catch (NamingException e)
{
// ignore
}
+
+ // stop thread pool
+ threadPool.shutdown();
+
+ // stop the watchdog
+ watchDog.shutdown();
+
+ for (URI eventSourceNS : eventSourceMapping.keySet())
+ {
+ removeEventSource(eventSourceNS);
+ }
}
private static URI generateSubscriptionID()
@@ -623,7 +625,7 @@
{
private ConcurrentMap<URI, List<Subscription>> subscriptions;
- private boolean active = true;
+ private volatile boolean active = true;
private Thread worker;
public WatchDog(ConcurrentMap<URI, List<Subscription>> subscriptions)
@@ -635,7 +637,6 @@
{
while (active)
{
-
for (List<Subscription> subscriptions : subscriptionMapping.values())
{
for (Subscription s : subscriptions)
@@ -654,7 +655,10 @@
}
catch (InterruptedException e)
{
- log.error(e);
+ if (active)
+ {
+ log.error(e);
+ }
}
}
}
@@ -669,6 +673,21 @@
public void shutdown()
{
this.active = false;
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ {
+ worker.interrupt();
+ }
+ else
+ {
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run()
+ {
+ worker.interrupt();
+ return null;
+ }
+ });
+ }
}
}
Show replies by date