mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Nice thingy for watching and killing unruly processes
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package processing.app.tools.android;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class ProcessRegistry {
|
||||
private static final Set<Process> REGISTRY = Collections
|
||||
.synchronizedSet(new HashSet<Process>());
|
||||
|
||||
static {
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (REGISTRY) {
|
||||
for (final Process p : REGISTRY) {
|
||||
try {
|
||||
System.err.println("Cleaning up rogue process " + p);
|
||||
p.destroy();
|
||||
} catch (final Exception drop) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* When starting up a process
|
||||
* @param p
|
||||
*/
|
||||
public static void watch(final Process p) {
|
||||
REGISTRY.add(p);
|
||||
}
|
||||
|
||||
public static void unwatch(final Process p) {
|
||||
REGISTRY.remove(p);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user