summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-09-13 14:14:30 (EDT)
committerEike Stepper2007-09-13 14:14:30 (EDT)
commit2be60a28c173f9f0815e9b4f6a110d0e2f575882 (patch)
tree83daadb8c8c14931cc421bc1a706a3392accc33e
parent067a4e6039b16faf91ca5b2aca6706f01464dd7a (diff)
downloadcdo-2be60a28c173f9f0815e9b4f6a110d0e2f575882.zip
cdo-2be60a28c173f9f0815e9b4f6a110d0e2f575882.tar.gz
cdo-2be60a28c173f9f0815e9b4f6a110d0e2f575882.tar.bz2
Fixed JRE 1.6 non-compliance.
http://www.nabble.com/Backwards-incompatible-API-Change-in-1.6-ExecutorService--t3909325.html
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/NamedExecutorService.java137
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/ExecutorServiceFactory.java23
2 files changed, 20 insertions, 140 deletions
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/NamedExecutorService.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/NamedExecutorService.java
deleted file mode 100644
index e8ec590..0000000
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/NamedExecutorService.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.net4j.internal.util.concurrent;
-
-import java.text.MessageFormat;
-import java.util.Collection;
-import java.util.List;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-/**
- * @author Eike Stepper
- */
-public class NamedExecutorService implements ExecutorService
-{
- public static final ThreadFactory THREAD_FACTORY = new ThreadFactory()
- {
- public Thread newThread(Runnable r)
- {
- Thread thread = new Thread(r);
- thread.setDaemon(true);
- return thread;
- }
- };
-
- private String name;
-
- private ExecutorService delegate;
-
- public NamedExecutorService(String name, ExecutorService delegate)
- {
- this.name = name;
- this.delegate = delegate;
- }
-
- public NamedExecutorService(String name, ThreadFactory threadFactory)
- {
- this(name, Executors.newCachedThreadPool(threadFactory));
- }
-
- public NamedExecutorService(String name)
- {
- this(name, THREAD_FACTORY);
- }
-
- public NamedExecutorService()
- {
- this("DaemonThreadPool");
- }
-
- public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
- {
- return delegate.awaitTermination(timeout, unit);
- }
-
- public void execute(Runnable command)
- {
- delegate.execute(command);
- }
-
- public <T> List<Future<T>> invokeAll(Collection<Callable<T>> tasks, long timeout, TimeUnit unit)
- throws InterruptedException
- {
- return delegate.invokeAll(tasks, timeout, unit);
- }
-
- public <T> List<Future<T>> invokeAll(Collection<Callable<T>> tasks) throws InterruptedException
- {
- return delegate.invokeAll(tasks);
- }
-
- public <T> T invokeAny(Collection<Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException,
- ExecutionException, TimeoutException
- {
- return delegate.invokeAny(tasks, timeout, unit);
- }
-
- public <T> T invokeAny(Collection<Callable<T>> tasks) throws InterruptedException, ExecutionException
- {
- return delegate.invokeAny(tasks);
- }
-
- public boolean isShutdown()
- {
- return delegate.isShutdown();
- }
-
- public boolean isTerminated()
- {
- return delegate.isTerminated();
- }
-
- public void shutdown()
- {
- delegate.shutdown();
- }
-
- public List<Runnable> shutdownNow()
- {
- return delegate.shutdownNow();
- }
-
- public <T> Future<T> submit(Callable<T> task)
- {
- return delegate.submit(task);
- }
-
- public <T> Future<T> submit(Runnable task, T result)
- {
- return delegate.submit(task, result);
- }
-
- public Future<?> submit(Runnable task)
- {
- return delegate.submit(task);
- }
-
- @Override
- public String toString()
- {
- return MessageFormat.format("ExecutorService[{0}]", name); //$NON-NLS-1$
- }
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/ExecutorServiceFactory.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/ExecutorServiceFactory.java
index 1523c79..c9c9103 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/ExecutorServiceFactory.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/ExecutorServiceFactory.java
@@ -10,11 +10,12 @@
**************************************************************************/
package org.eclipse.internal.net4j;
-import org.eclipse.net4j.internal.util.concurrent.NamedExecutorService;
import org.eclipse.net4j.internal.util.factory.Factory;
import org.eclipse.net4j.util.container.IManagedContainer;
import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
/**
* @author Eike Stepper
@@ -25,14 +26,30 @@ public class ExecutorServiceFactory extends Factory
public static final String TYPE = "default";
+ public static final String DEFAULT_THREAD_GROUP_NAME = "net4j";
+
public ExecutorServiceFactory()
{
super(PRODUCT_GROUP, TYPE);
}
- public ExecutorService create(String description)
+ public ExecutorService create(String threadGroupName)
{
- return new NamedExecutorService();
+ if (threadGroupName == null)
+ {
+ threadGroupName = DEFAULT_THREAD_GROUP_NAME;
+ }
+
+ final ThreadGroup threadGroup = new ThreadGroup(threadGroupName);
+ return Executors.newCachedThreadPool(new ThreadFactory()
+ {
+ public Thread newThread(Runnable r)
+ {
+ Thread thread = new Thread(threadGroup, r);
+ thread.setDaemon(true);
+ return thread;
+ }
+ });
}
public static ExecutorService get(IManagedContainer container)