Something like this:
ExecutorService threadPool = Executors.newCachedThreadPool();
Runnable task = new Runnable() {
@Override
public void run() {
int i = 0;
while (i < 10) {
try {
Thread.sleep(2000);
}
catch (Exception e) {
}
System.out.println("Running" + i);
}
}
};
threadPool.execute(task);
//TODO: Check to see if "task" is still running.
I wanted to check to see if the Runnable is currently running in the thread pool when the Runnable is executed. Is it possible to do this? The State enumeration is something copied from Thread class. I wasn’t sure if Runnable has one or similar.