0
陈述问题恢复与线程按钮的功能: -Eclipse的RCP--怎么办暂停/使用(等待和通知)
我有一个UI按钮“执行” - 这将启动一个大背景按顺序循环处理不同的线程。 一旦该进程启动按钮上的文字将被切换到“暂停” 现在的“暂停”的出版社,我需要挂起线程执行和“恢复”终于将通知继续前进。
按下按钮“执行”,线程被启动,按钮切换到‘暂停’,如果我按暂停,线程是suspended.But我不能恢复运行thread.If我检查线程状态在继续按钮按下事件,我得到值= 0相当于NONe。请帮忙。下面是我的代码....
块引用
performBButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
Button btnToggle = (Button) e.getSource();
MyJob myJob = new MyJob();
if (btnToggle.getText().equalsIgnoreCase("Perform")) {
btnToggle.setText("Pause");
myJob.schedule();
}
else if (btnToggle.getText().equals("Pause")) {
buttonToggle.setText("Resume");
isPaused=!isPaused;
}
else if (btnToggle.getText().equals("Resume")) {
buttonToggle.setText("Pause");
isPaused=!isPaused;
synchronized (myJob) {
myJob.notify();
}
}
}
});
class MYJob extends Job{
public void run(IProgessMonito monitor) {
@Override
public void run() {
for (int i=0;i<50000;i++) {
System.out.println("Iteration "+i +isPaused);
synchronized (this) {
if (isPaused) {
wait();
}
}
}
Thread.sleep(1000);//I have removed try catch while pasting here
}
}
}
}