当前位置: 技术问答>java相关
java程序执行中如何判断时间过期?
来源: 互联网 发布时间:2017-04-21
本文导语: C/S项目,,java swing 和RMI 结合的,, 怎么判断执行中时间过期? 各位给点实施建议?谢谢 | 仅供参考,没有去调。 public class CheckTime extends Thread { int time; boolean timeExpired = ...
C/S项目,,java swing 和RMI 结合的,,
怎么判断执行中时间过期?
各位给点实施建议?谢谢
怎么判断执行中时间过期?
各位给点实施建议?谢谢
|
仅供参考,没有去调。
public class CheckTime extends Thread {
int time;
boolean timeExpired = false;
public CheckTime(int time) { // second
this.time = time;
}
public void run() {
try{
sleep(time*1000);
}catch(Exception e){}
timeExpired = true;
}
public boolean expired() { return timeExpired;}
}
class Testing {
public static void main(String[] a) {
CheckTime t = new CheckTime(3);
t.start();
while(!t.expired()) {
// do your processing
}
}
}
public class CheckTime extends Thread {
int time;
boolean timeExpired = false;
public CheckTime(int time) { // second
this.time = time;
}
public void run() {
try{
sleep(time*1000);
}catch(Exception e){}
timeExpired = true;
}
public boolean expired() { return timeExpired;}
}
class Testing {
public static void main(String[] a) {
CheckTime t = new CheckTime(3);
t.start();
while(!t.expired()) {
// do your processing
}
}
}