Skip to content

Commit

Permalink
Fix isShutdown() always return true (#1426)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxiaoguang64 authored and ralf0131 committed May 9, 2018
1 parent 04c93e8 commit 0592e84
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ public class ExecutorUtil {
new LinkedBlockingQueue<Runnable>(100),
new NamedThreadFactory("Close-ExecutorService-Timer", true));

public static boolean isShutdown(Executor executor) {
public static boolean isTerminated(Executor executor) {
if (executor instanceof ExecutorService) {
if (((ExecutorService) executor).isShutdown()) {
if (((ExecutorService) executor).isTerminated()) {
return true;
}
}
return false;
}

public static void gracefulShutdown(Executor executor, int timeout) {
if (!(executor instanceof ExecutorService) || isShutdown(executor)) {
if (!(executor instanceof ExecutorService) || isTerminated(executor)) {
return;
}
final ExecutorService es = (ExecutorService) executor;
Expand All @@ -63,13 +63,13 @@ public static void gracefulShutdown(Executor executor, int timeout) {
es.shutdownNow();
Thread.currentThread().interrupt();
}
if (!isShutdown(es)) {
if (!isTerminated(es)) {
newThreadToCloseExecutor(es);
}
}

public static void shutdownNow(Executor executor, final int timeout) {
if (!(executor instanceof ExecutorService) || isShutdown(executor)) {
if (!(executor instanceof ExecutorService) || isTerminated(executor)) {
return;
}
final ExecutorService es = (ExecutorService) executor;
Expand All @@ -85,13 +85,13 @@ public static void shutdownNow(Executor executor, final int timeout) {
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
if (!isShutdown(es)) {
if (!isTerminated(es)) {
newThreadToCloseExecutor(es);
}
}

private static void newThreadToCloseExecutor(final ExecutorService es) {
if (!isShutdown(es)) {
if (!isTerminated(es)) {
shutdownExecutor.execute(new Runnable() {
@Override
public void run() {
Expand Down

0 comments on commit 0592e84

Please sign in to comment.