Skip to content

Commit

Permalink
Merge branch 'bug/36-execution-thread-vanished' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Scholl committed Jul 1, 2014
2 parents c02e685 + 721663b commit c3f093a
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions src/main/java/de/cismet/commons/concurrency/CismetExecutors.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
import java.lang.Thread.UncaughtExceptionHandler;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.AbstractExecutorService;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -343,10 +342,6 @@ public <T> T invokeAny(final Collection<? extends Callable<T>> arg0, final long
*/
public static final class UEHThreadPoolExecutor extends ThreadPoolExecutor {

//~ Instance fields ----------------------------------------------------

private final transient Map<Runnable, Thread> runnableToThreadMap;

//~ Constructors -------------------------------------------------------

/**
Expand Down Expand Up @@ -375,27 +370,12 @@ public UEHThreadPoolExecutor(final int corePoolSize,
final ThreadFactory threadFactory,
final RejectedExecutionHandler rejectHandler) {
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, rejectHandler);

this.runnableToThreadMap = new HashMap<Runnable, Thread>();
}

//~ Methods ------------------------------------------------------------

@Override
protected void beforeExecute(final Thread t, final Runnable r) {
super.beforeExecute(t, r);

runnableToThreadMap.put(r, t);
}

@Override
protected void afterExecute(final Runnable r, final Throwable t) {
super.afterExecute(r, t);

final Thread thread = runnableToThreadMap.remove(r);

assert thread != null : "expected associated thread"; // NOI18N

if ((t == null) && (r instanceof Future)) {
Throwable thrown = null;
try {
Expand All @@ -411,6 +391,8 @@ protected void afterExecute(final Runnable r, final Throwable t) {
}

if (thrown != null) {
// the current thread is actually the one that executes the task
final Thread thread = Thread.currentThread();
final Thread.UncaughtExceptionHandler handler = thread.getUncaughtExceptionHandler();
if (handler == null) {
final Thread.UncaughtExceptionHandler groupHandler = thread.getThreadGroup();
Expand Down

0 comments on commit c3f093a

Please sign in to comment.