标签:
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;
}
}
}
标签:
原文地址:http://my.oschina.net/u/435726/blog/388995