[jboss-cvs] JBossAS SVN: r91809 - projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jul 30 00:02:49 EDT 2009
Author: david.lloyd at jboss.com
Date: 2009-07-30 00:02:48 -0400 (Thu, 30 Jul 2009)
New Revision: 91809
Modified:
projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/ConfigurableExecutor.java
projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/DirectExecutor.java
projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossExecutors.java
projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/ResettingDirectExecutor.java
Log:
Add docs, fix bug in ResettingDirectExecutor and hide it behind a factory method
Modified: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/ConfigurableExecutor.java
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/ConfigurableExecutor.java 2009-07-30 03:51:01 UTC (rev 91808)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/ConfigurableExecutor.java 2009-07-30 04:02:48 UTC (rev 91809)
@@ -25,7 +25,7 @@
import java.util.concurrent.Executor;
/**
- *
+ * An executor upon which tasks may be executed
*/
public interface ConfigurableExecutor {
void execute(Runnable task, DirectExecutor taskExecutor, RejectionPolicy policy, Executor handoffExecutor);
Modified: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/DirectExecutor.java
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/DirectExecutor.java 2009-07-30 03:51:01 UTC (rev 91808)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/DirectExecutor.java 2009-07-30 04:02:48 UTC (rev 91809)
@@ -27,6 +27,26 @@
/**
* A direct executor. Such an executor is required to run the given task in the current thread rather than
* delegate to a thread pool.
+ *
+ * @see JBossExecutors#directExecutor()
+ * @see JBossExecutors#rejectingExecutor()
+ * @see JBossExecutors#discardingExecutor()
+ * @see JBossExecutors#privilegedExecutor(org.jboss.threads.DirectExecutor, java.security.AccessControlContext)
+ * @see JBossExecutors#contextClassLoaderExecutor(org.jboss.threads.DirectExecutor, java.lang.ClassLoader)
+ * @see JBossExecutors#threadNameExecutor(org.jboss.threads.DirectExecutor, java.lang.String)
+ * @see JBossExecutors#threadNameNotateExecutor(org.jboss.threads.DirectExecutor, java.lang.String)
+ * @see JBossExecutors#exceptionLoggingExecutor(org.jboss.threads.DirectExecutor, java.lang.Object)
+ * @see JBossExecutors#resettingExecutor(org.jboss.threads.DirectExecutor)
*/
public interface DirectExecutor extends Executor {
+
+ /**
+ * Executes the given command in the calling thread.
+ *
+ * @param command the runnable task
+ *
+ * @throws java.util.concurrent.RejectedExecutionException if this task cannot be accepted for execution
+ * @throws NullPointerException if command is null
+ */
+ void execute(Runnable command);
}
Modified: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossExecutors.java
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossExecutors.java 2009-07-30 03:51:01 UTC (rev 91808)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossExecutors.java 2009-07-30 04:02:48 UTC (rev 91809)
@@ -262,6 +262,19 @@
}
/**
+ * Create a direct executor which delegates tasks to the given executor, and then clears <b>all</b> thread-local
+ * data after each task completes (regardless of outcome). You must have the {@link RuntimePermission}{@code ("modifyThread")}
+ * permission to use this method.
+ *
+ * @param delegate the delegate direct executor
+ * @return a resetting executor
+ * @throws SecurityException if the caller does not have the {@link RuntimePermission}{@code ("modifyThread")} permission
+ */
+ public static DirectExecutor resettingExecutor(final DirectExecutor delegate) throws SecurityException {
+ return new ResettingDirectExecutor(delegate);
+ }
+
+ /**
* Create an executor that executes each task in a new thread.
*
* @param factory the thread factory to use
Modified: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/ResettingDirectExecutor.java
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/ResettingDirectExecutor.java 2009-07-30 03:51:01 UTC (rev 91808)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/ResettingDirectExecutor.java 2009-07-30 04:02:48 UTC (rev 91809)
@@ -29,7 +29,7 @@
/**
* A direct executor which resets the thread-local maps after every task (if possible).
*/
-public class ResettingDirectExecutor implements DirectExecutor {
+final class ResettingDirectExecutor implements DirectExecutor {
private final DirectExecutor delegate;
private static final Field THREAD_LOCAL_MAP_FIELD;
@@ -53,7 +53,7 @@
public Field run() {
final Field field;
try {
- field = Thread.class.getDeclaredField("threadLocals");
+ field = Thread.class.getDeclaredField("inheritableThreadLocals");
field.setAccessible(true);
} catch (NoSuchFieldException e) {
return null;
@@ -68,7 +68,7 @@
*
* @param delegate the executor which will actually execute the task
*/
- public ResettingDirectExecutor(DirectExecutor delegate) {
+ ResettingDirectExecutor(DirectExecutor delegate) {
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(MODIFY_THREAD_PERMISSION);
More information about the jboss-cvs-commits
mailing list