If you’re using Java 8 or later you could simply use the new waitFor with timeout:
Process p = ...
if(!p.waitFor(1, TimeUnit.MINUTES)) {
//timeout - kill the process.
p.destroy(); // consider using destroyForcibly instead
}
More Related Contents:
- Executing a Java application in a separate process
- Redirect Runtime.getRuntime().exec() output with System.setOut();
- Runtime.exec on argument containing multiple spaces
- How to timeout a thread
- How to make pipes work with Runtime.exec()?
- How to get a list of current open windows/process with Java?
- How to stop java process gracefully?
- How do I launch a completely independent process from a Java program?
- How to get PID of process I’ve just started within java program?
- Spring Boot REST API – request timeout?
- List of useful environment settings in Java
- Dynamically Changing log4j log level
- How to Daemonize a Java Program?
- How to set timeout in Retrofit library?
- Java HTTP Client Request with defined timeout
- How to use “cd” command using Java runtime?
- How to set working directory with ProcessBuilder
- Change a method at runtime via a hot swap mechanism
- how to change the name of a Java application process?
- How to find and kill running Win-Processes from within Java?
- What is the difference between connection and read timeout for sockets?
- Compile time vs Run time Dependency – Java
- How to get a JavaDoc of a method at run time?
- How to set a default query timeout with JPA and Hibernate?
- Where is the “server log” for Tomcat when running externally from IntelliJ Ultimate?
- Java: set timeout on a certain block of code?
- check if some exe program is running on the windows
- Launch Firefox and Wait until it is Closed
- How JVM stack, heap and threads are mapped to physical memory or operation system
- Generating Enums Dynamically