你代码中的sleep()跟this.sleep()作用是一样的,可能调用的是主线程的sleep()方法,改成这样试试:
Job job = new Job("Job Name"){
protected IStatus run(IProgressMonitor monitor) {
System.out.println("------>Job.1");
Thread.sleep();
System.out.println("--------->Job.2");
return Status.OK_STATUS;
}
};
job.schedule(2000);
Job job = new Job("Job Name"){
protected IStatus run(IProgressMonitor monitor) {
System.out.println("------>Job.1");
Thread.sleep();
System.out.println("--------->Job.2");
return Status.OK_STATUS;
}
};
job.schedule(2000);
Thread.sleep(2000);
If this job is not currently waiting to be run, this method has no effect.
你在调用sleep()的时候线程已经在运行了,当然不会有任何效果。
Job要结合IJobManager来使用
public final boolean sleep()
Returns:
false if the job is currently running (and thus cannot be put to sleep), and true in all other cases
你打印一下它的return看看,应该就是false了