Is there a way (either builtin, or with external library) to have a time limit for Process.waitFor
? It's a good safeguard against buggy processes, and implementing it with an extra thread and an interrupt seems like reinventing the wheel.
Asked
Active
Viewed 717 times
1

Elazar Leibovich
- 32,750
- 33
- 122
- 169
-
Have you looked at [ExecutorService](http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ExecutorService.html)? – miku Jan 16 '12 at 22:20
-
You might be interested in ExecutorService which has timeouts builtin http://stackoverflow.com/questions/2733356/killing-thread-after-some-specified-time-limit-in-java – ChristopheD Jan 16 '12 at 22:21
-
@miku ExecutorService is a thread in disguise. It's rather low level. I'd rather something builting that would allow me, say to destroy the process if timeout exceeds. `Processes.waitFor(p,100)` is more readable than `svc.execute(new Runnable() {void run() {p.waitFor;}....)` – Elazar Leibovich Jan 16 '12 at 22:36