Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix isShutdown always return true #1426

Merged
merged 2 commits into from
May 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
public void run() {
try {
Expand Down Expand Up @@ -122,4 +122,4 @@ public static URL setThreadName(URL url, String defaultName) {
url = url.addParameter(Constants.THREAD_NAME_KEY, name);
return url;
}
}
}