Skip to content

Instantly share code, notes, and snippets.

@Depicus
Created January 14, 2015 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Depicus/4d7857a09791fc245db7 to your computer and use it in GitHub Desktop.
Save Depicus/4d7857a09791fc245db7 to your computer and use it in GitHub Desktop.
Kill a java app that is stuck and over running.
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
Thread t = new Thread(new Runnable() {
public void run() {
// stuff here that was in main
logger.debug("threaded started ");
try {
Thread.sleep(60 * 1000);
} catch (InterruptedException ex) {
java.util.logging.Logger.getLogger(tester.class.getName()).log(Level.SEVERE, null, ex);
}
logger.debug("threaded finished ");
}
});
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(t, out);
executor.shutdown();
if (executor.awaitTermination(30, TimeUnit.SECONDS)) {
logger.info("All threads done with their jobs");
}
else
{
logger.error("we cancelled the thread");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment