Created
January 14, 2015 21:44
-
-
Save Depicus/4d7857a09791fc245db7 to your computer and use it in GitHub Desktop.
Kill a java app that is stuck and over running.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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