📄 testisalive.java
字号:
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Timer;
import java.util.TimerTask;
public class TestIsAlive extends TimerTask {
private ObjectInputStream tis;
private ObjectOutputStream tos;
private String name;
public boolean ok = true;
public TestIsAlive(ObjectInputStream is,ObjectOutputStream os, String s){
super();
tis = is;
tos = os;
name = s;
}
public void run(){
try {
tos.writeObject(Msg.TESTMSG(name));
tos.flush();
ok = false;
final Thread thread = new Thread(){
public void run(){
Msg msg;
try {
msg = (Msg)tis.readObject();
if (msg.gettype() == Msg.OK) ok = true;
else if(msg.gettype() == Msg.TEST){
ok = true;
tos.writeObject(Msg.OKMSG(name));
tos.flush();
}
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
};
Timer timer = new Timer();
timer.schedule(new TimerTask(){
public void run(){
if (ok == false){
thread.stop();
}
}
}, 5000L);
if(ok == false){
this.cancel();
}
} catch (IOException e) {
// TODO 自动生成 catch 块
ok = false;
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -