-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJLaunchPad.java
69 lines (61 loc) · 1.63 KB
/
JLaunchPad.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.sql.Time;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level;
public class JLaunchPad {
int sec = 1000;
int min = 60 * sec;
int hr = 60 * min;
int delay = 20 * min;
Process javaProcess;
Timer tm;
public JLaunchPad() {
javaProcess = null;
tm = null;
}
public static void main(String[] args) throws Exception{
new JLaunchPad().launch();
}
public void consumeOutput(Process p) {
InputStream inStream = p.getInputStream();
InputStreamReader inStreamReader = new InputStreamReader(inStream);
BufferedReader bReader = new BufferedReader(inStreamReader);
String line = null;
try {
while ( (line = bReader.readLine()) != null) System.out.println(line);
} catch (Exception e) {
tm.cancel();
tm = new Timer();
tm.schedule(new DestroyRelaunchTask() , 0);
}
}
public void launch(){
try {
javaProcess = Runtime.getRuntime().exec("java -classpath accjwrap.jar;.;mysql.jar Superbad McLovin12Four5 arg2");
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
System.out.println("Process launched @" + (new Date()).toString());
tm = new Timer();
tm.schedule(new DestroyRelaunchTask() , delay);
consumeOutput(javaProcess);
}
public void destroyRelaunch(){
if (javaProcess!=null) {
javaProcess.destroy();
System.out.println("Process destroyed @" + (new Date()).toString());
}
launch();
}
public class DestroyRelaunchTask extends TimerTask {
public void run() {
destroyRelaunch();
}
}
}