public class BaseJunit {
private Timer timer;
private Object mSync = new Object();
protected void Wait() {
synchronized (mSync) {
if (timer != null) {
timer.cancel();
timer.purge();
timer = null;
}
timer = new Timer();
timer.schedule(task, 3 * 1000);
}
synchronized (mSync) {
try {
mSync.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
protected TimerTask task = new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
Notify();
}
};
protected void Notify() {
synchronized (mSync) {
mSync.notifyAll();
}
}
protected void removeTimerTask() {
synchronized (mSync) {
if (timer != null) {
timer.cancel();
timer.purge();
timer = null;
}
}
}
时间: 2024-11-02 05:46:22