You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2009/05/18 15:53:40 UTC
svn commit: r775950 - in /cxf/branches/2.1.x-fixes: ./
rt/core/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java
rt/core/src/main/java/org/apache/cxf/workqueue/WorkQueueManagerImpl.java
Author: dkulp
Date: Mon May 18 13:53:40 2009
New Revision: 775950
URL: http://svn.apache.org/viewvc?rev=775950&view=rev
Log:
Merged revisions 774851 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r774851 | dkulp | 2009-05-14 13:40:59 -0400 (Thu, 14 May 2009) | 2 lines
[CXF-2220] Attempt to fix classloader issues with the AutomaticWorkQueueImpl
........
Modified:
cxf/branches/2.1.x-fixes/ (props changed)
cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java
cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/workqueue/WorkQueueManagerImpl.java
Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon May 18 13:53:40 2009
@@ -1 +1 @@
-/cxf/trunk:743446,753380,753397,753421,754585,755365,757499,757859,757899,757935,757951,758195,758303,758308,758378,758690,758910,759890,759961,759963-759964,759966,760029,760073,760150,760171,760178,760198,760212,760456,760468,760582,760938,761094,761113,761120,761317,761759,761789,762393,762518,762567,763200,763272,763495,763854,763931,763942,763953,764033-764034,764581,764599-764606,764887,765357,766013,766058,766100-766101,766763,766770,766860,766962-766963,767159,767191,767927,771416,772143,772402,772658,772714,773009-773010,773027,773049,773146,773581,773691,773693,774446-774496,774558,774760
+/cxf/trunk:743446,753380,753397,753421,754585,755365,757499,757859,757899,757935,757951,758195,758303,758308,758378,758690,758910,759890,759961,759963-759964,759966,760029,760073,760150,760171,760178,760198,760212,760456,760468,760582,760938,761094,761113,761120,761317,761759,761789,762393,762518,762567,763200,763272,763495,763854,763931,763942,763953,764033-764034,764581,764599-764606,764887,765357,766013,766058,766100-766101,766763,766770,766860,766962-766963,767159,767191,767927,771416,772143,772402,772658,772714,773009-773010,773027,773049,773146,773581,773691,773693,774446-774496,774558,774760,774851
Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java?rev=775950&r1=775949&r2=775950&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java (original)
+++ cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java Mon May 18 13:53:40 2009
@@ -19,10 +19,14 @@
package org.apache.cxf.workqueue;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionException;
+import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -43,30 +47,44 @@
WorkQueueManagerImpl manager;
String name = "default";
-
public AutomaticWorkQueueImpl() {
this(DEFAULT_MAX_QUEUE_SIZE);
}
+ public AutomaticWorkQueueImpl(String name) {
+ this(DEFAULT_MAX_QUEUE_SIZE, name);
+ }
public AutomaticWorkQueueImpl(int max) {
+ this(max, "default");
+ }
+ public AutomaticWorkQueueImpl(int max, String name) {
this(max,
0,
25,
5,
- 2 * 60 * 1000L);
+ 2 * 60 * 1000L,
+ name);
}
-
public AutomaticWorkQueueImpl(int mqs,
int initialThreads,
int highWaterMark,
int lowWaterMark,
long dequeueTimeout) {
+ this(mqs, initialThreads, highWaterMark, lowWaterMark, dequeueTimeout, "default");
+ }
+ public AutomaticWorkQueueImpl(int mqs,
+ int initialThreads,
+ int highWaterMark,
+ int lowWaterMark,
+ long dequeueTimeout,
+ String name) {
super(-1 == lowWaterMark ? Integer.MAX_VALUE : lowWaterMark,
-1 == highWaterMark ? Integer.MAX_VALUE : highWaterMark,
TimeUnit.MILLISECONDS.toMillis(dequeueTimeout), TimeUnit.MILLISECONDS,
mqs == -1 ? new LinkedBlockingQueue<Runnable>(DEFAULT_MAX_QUEUE_SIZE)
- : new LinkedBlockingQueue<Runnable>(mqs));
+ : new LinkedBlockingQueue<Runnable>(mqs),
+ createThreadFactory(name));
maxQueueSize = mqs == -1 ? DEFAULT_MAX_QUEUE_SIZE : mqs;
@@ -99,6 +117,66 @@
setCorePoolSize(lowWaterMark);
}
}
+ private static ThreadFactory createThreadFactory(final String name) {
+ ThreadGroup group;
+ try {
+ //Try and find the highest level ThreadGroup that we're allowed to use.
+ //That SHOULD allow the default classloader and thread locals and such
+ //to be the least likely to cause issues down the road.
+ group = AccessController.doPrivileged(
+ new PrivilegedAction<ThreadGroup>() {
+ public ThreadGroup run() {
+ ThreadGroup group = Thread.currentThread().getThreadGroup();
+ ThreadGroup parent = group;
+ try {
+ while (parent != null) {
+ group = parent;
+ parent = parent.getParent();
+ }
+ } catch (SecurityException se) {
+ //ignore - if we get here, the "group" is as high as
+ //the security manager will allow us to go. Use that one.
+ }
+ return new ThreadGroup(group, name + "-workqueue");
+ }
+ }
+ );
+ } catch (SecurityException e) {
+ group = new ThreadGroup(name + "-workqueue");
+ }
+
+ return new AWQThreadFactory(group, name);
+ }
+ static class AWQThreadFactory implements ThreadFactory {
+ final AtomicInteger threadNumber = new AtomicInteger(1);
+ ThreadGroup group;
+ String name;
+ ClassLoader loader;
+ AWQThreadFactory(ThreadGroup gp, String nm) {
+ group = gp;
+ name = nm;
+ //force the loader to be the loader of CXF, not the application loader
+ loader = AutomaticWorkQueueImpl.class.getClassLoader();
+ }
+ public Thread newThread(Runnable r) {
+ Thread t = new Thread(group,
+ r,
+ name + "-workqueue-" + threadNumber.getAndIncrement(),
+ 0);
+ t.setContextClassLoader(loader);
+ if (t.isDaemon()) {
+ t.setDaemon(false);
+ }
+ if (t.getPriority() != Thread.NORM_PRIORITY) {
+ t.setPriority(Thread.NORM_PRIORITY);
+ }
+ return t;
+ }
+ public void setName(String s) {
+ name = s;
+ }
+ }
+
@Resource(name = "org.apache.cxf.workqueue.WorkQueueManager")
public void setManager(WorkQueueManagerImpl mgr) {
manager = mgr;
@@ -109,6 +187,10 @@
public void setName(String s) {
name = s;
+ ThreadFactory factory = this.getThreadFactory();
+ if (factory instanceof AWQThreadFactory) {
+ ((AWQThreadFactory)factory).setName(s);
+ }
}
public String getName() {
return name;
@@ -148,8 +230,26 @@
return buf.toString();
}
+ public void execute(final Runnable command) {
+ //Grab the context classloader of this thread. We'll make sure we use that
+ //on the thread the runnable actually runs on.
+
+ final ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ Runnable r = new Runnable() {
+ public void run() {
+ ClassLoader orig = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(loader);
+ command.run();
+ } finally {
+ Thread.currentThread().setContextClassLoader(orig);
+ }
+ }
+ };
+ super.execute(r);
+ }
+
// WorkQueue interface
-
public void execute(Runnable work, long timeout) {
try {
execute(work);
Modified: cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/workqueue/WorkQueueManagerImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/workqueue/WorkQueueManagerImpl.java?rev=775950&r1=775949&r2=775950&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/workqueue/WorkQueueManagerImpl.java (original)
+++ cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/workqueue/WorkQueueManagerImpl.java Mon May 18 13:53:40 2009
@@ -118,7 +118,7 @@
}
private AutomaticWorkQueue createAutomaticWorkQueue() {
- AutomaticWorkQueueImpl impl = new AutomaticWorkQueueImpl();
+ AutomaticWorkQueueImpl impl = new AutomaticWorkQueueImpl("default");
impl.setManager(this);
impl.register();
return impl;