[jboss-cvs] JBossAS SVN: r89688 - 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
Tue Jun 2 14:08:13 EDT 2009
Author: david.lloyd at jboss.com
Date: 2009-06-02 14:08:13 -0400 (Tue, 02 Jun 2009)
New Revision: 89688
Added:
projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/ConfigurableExecutor.java
projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/QueuelessThreadPoolExecutor.java
Modified:
projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossExecutors.java
Log:
Add a queueless thread pool executor
Added: 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 (rev 0)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/ConfigurableExecutor.java 2009-06-02 18:08:13 UTC (rev 89688)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.threads;
+
+import java.util.concurrent.Executor;
+
+/**
+ *
+ */
+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/JBossExecutors.java
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossExecutors.java 2009-06-02 17:47:17 UTC (rev 89687)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossExecutors.java 2009-06-02 18:08:13 UTC (rev 89688)
@@ -367,4 +367,21 @@
public static ScheduledExecutorService protectedScheduledExecutorService(final ScheduledExecutorService target) {
return new ProtectedScheduledExecutorService(target);
}
+
+ /**
+ * Wrap a configurable executor with a preconfigured executor.
+ *
+ * @param configurableExecutor the configurable executor
+ * @param taskExecutor the direct executor to wrap tasks in, or {@code null} for none
+ * @param rejectionPolicy the rejection policy for the new executor
+ * @param handoffExecutor the handoff executor to use in the event of a rejected task
+ * @return a configured executor
+ */
+ public static Executor configuredExecutor(final ConfigurableExecutor configurableExecutor, final DirectExecutor taskExecutor, final RejectionPolicy rejectionPolicy, final Executor handoffExecutor) {
+ return new Executor() {
+ public void execute(final Runnable command) {
+ configurableExecutor.execute(command, taskExecutor, rejectionPolicy, handoffExecutor);
+ }
+ };
+ }
}
Added: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/QueuelessThreadPoolExecutor.java
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/QueuelessThreadPoolExecutor.java (rev 0)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/QueuelessThreadPoolExecutor.java 2009-06-02 18:08:13 UTC (rev 89688)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.threads;
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Create a queueless thread pool executor.
+ */
+public final class QueuelessThreadPoolExecutor extends ThreadPoolExecutor implements ConfigurableExecutor {
+
+ /**
+ * Construct a new instance.
+ *
+ * @param keepAliveTime the thread keepalive time
+ * @param unit the time unit
+ */
+ public QueuelessThreadPoolExecutor(final long keepAliveTime, final TimeUnit unit) {
+ super(0, Integer.MAX_VALUE, keepAliveTime, unit, new SynchronousQueue<Runnable>());
+ }
+
+ /**
+ * Execute a task. Tasks on a queueless executor are never rejected (unless the pool is shut down).
+ *
+ * @param task the task to execute
+ * @param taskExecutor the direct executor to use, or {@code null} to execute the task as-is
+ * @param policy the rejection policy (ignored)
+ * @param handoffExecutor the handoff executor (ignored)
+ */
+ public void execute(final Runnable task, final DirectExecutor taskExecutor, final RejectionPolicy policy, final Executor handoffExecutor) {
+ execute(taskExecutor == null || taskExecutor == JBossExecutors.directExecutor() ? task : JBossExecutors.executorTask(taskExecutor, task));
+ }
+}
More information about the jboss-cvs-commits
mailing list