io.deepsense.neptune.clientlibrary.threads.JobInternalThread Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of neptune-client-library Show documentation
Show all versions of neptune-client-library Show documentation
Enables integration with Neptune in your Java code
/**
* Copyright (c) 2016, CodiLime Inc.
*/
package io.deepsense.neptune.clientlibrary.threads;
import com.google.common.base.Preconditions;
import io.deepsense.neptune.clientlibrary.utils.ThreadBrowser;
public abstract class JobInternalThread extends Thread {
private final ThreadBrowser threadBrowser;
private volatile boolean shutdownRequested;
public JobInternalThread(ThreadBrowser threadBrowser, String name, boolean isDaemon) {
this.threadBrowser = Preconditions.checkNotNull(threadBrowser);
this.setName("neptune-internal-" + Preconditions.checkNotNull(name));
this.setDaemon(isDaemon);
}
@Override
public void interrupt() {
throw new RuntimeException("Neptune threads shouldn't use interrupt(). Use gracefulShutdown() instead.");
}
public void gracefulShutdown() {
shutdownRequested = true;
}
public boolean isShutdownRequested() {
return shutdownRequested;
}
public boolean areOtherThreadsAlive() {
return threadBrowser.getActiveThreads().stream()
.filter(thread -> thread != this
&& !isInternalJavaThread(thread)
&& thread.isAlive()
&& !thread.isDaemon())
.findAny()
.isPresent();
}
private static boolean isInternalJavaThread(Thread thread) {
return thread.getName().equals("DestroyJavaVM");
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy