summaryrefslogtreecommitdiff
path: root/qpid/java/common/src/main
diff options
context:
space:
mode:
authorAlex Rudyy <orudyy@apache.org>2014-10-23 16:04:24 +0000
committerAlex Rudyy <orudyy@apache.org>2014-10-23 16:04:24 +0000
commit882aa4e7dba8471ca3616bd431146a18645574a9 (patch)
tree97fc1f9c2d5ff30ca3a8e251e2067d4d9bbc541b /qpid/java/common/src/main
parentb6d5cb94f83b5a8424f43bcd9495810351272373 (diff)
downloadqpid-python-882aa4e7dba8471ca3616bd431146a18645574a9.tar.gz
QPID-6184: Add special thread factory to use with Executors which creates Threads with empty inherited AccessControlContext
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1633862 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/common/src/main')
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/pool/ReferenceCountingExecutorService.java7
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/pool/SuppressingInheritedAccessControlContextThreadFactory.java50
2 files changed, 52 insertions, 5 deletions
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/pool/ReferenceCountingExecutorService.java b/qpid/java/common/src/main/java/org/apache/qpid/pool/ReferenceCountingExecutorService.java
index a6df71464b..c9fbd824c5 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/pool/ReferenceCountingExecutorService.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/pool/ReferenceCountingExecutorService.java
@@ -21,7 +21,6 @@
package org.apache.qpid.pool;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
@@ -82,10 +81,8 @@ public class ReferenceCountingExecutorService
/** Holds the number of executor threads to create. */
private int _poolSize = Integer.getInteger("amqj.read_write_pool_size", DEFAULT_POOL_SIZE);
- /** Thread Factory used to create thread of the pool. Uses the default implementation provided by
- * {@link java.util.concurrent.Executors#defaultThreadFactory()} unless reset by the caller.
- */
- private ThreadFactory _threadFactory = Executors.defaultThreadFactory();
+ /** Thread Factory used to create thread of the pool. */
+ private ThreadFactory _threadFactory = new SuppressingInheritedAccessControlContextThreadFactory();
/**
* Retrieves the singleton instance of this reference counter.
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/pool/SuppressingInheritedAccessControlContextThreadFactory.java b/qpid/java/common/src/main/java/org/apache/qpid/pool/SuppressingInheritedAccessControlContextThreadFactory.java
new file mode 100644
index 0000000000..37ce8f5d67
--- /dev/null
+++ b/qpid/java/common/src/main/java/org/apache/qpid/pool/SuppressingInheritedAccessControlContextThreadFactory.java
@@ -0,0 +1,50 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.pool;
+
+
+import javax.security.auth.Subject;
+import java.security.PrivilegedAction;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+
+/**
+ * <code>ThreadFactory</code> to create threads with empty inherited <code>java.security.AccessControlContext</code>
+ * <p></p>
+ * It delegates thread creation to <code>Executors</code> default thread factory.
+ */
+public class SuppressingInheritedAccessControlContextThreadFactory implements ThreadFactory
+{
+ private final ThreadFactory _defaultThreadFactory = Executors.defaultThreadFactory();
+
+ @Override
+ public Thread newThread(final Runnable runnable)
+ {
+ return Subject.doAsPrivileged(null, new PrivilegedAction<Thread>()
+ {
+ @Override
+ public Thread run()
+ {
+ return _defaultThreadFactory.newThread(runnable);
+ }
+ }, null);
+ }
+}