有没有办法让eclipse中的特定插件启动所有作业? 这里我们在命令行模式下运行eclipse。我们在一个插件中开始几个工作。在某些情况下,即使在作业完成之前,插件也会终止。已经决定等待Activator.stop()中特定插件启动的所有作业。我想知道是否有可能通过特定插件启动所有工作。
答案 0 :(得分:2)
覆盖这样的Job类。
public class MyPluginJob extends Job
{
private String jobFamily;
public MyPluginJob(String name, String jobFamily)
{
super(name);
this.jobFamily = jobFamily;
}
@Override
public boolean belongsTo(Object family)
{
return this.jobFamily.equals(family);
}
}
而且,您将以姓氏开始工作
Job job = new MyPluginJob("Update info", "Your_plugin_job_family_name")
{
@Override
protected IStatus run(IProgressMonitor monitor)
{
//do whatever you want
return Status.OK_STATUS;
}
};
job.schedule();
现在,通过此次通话获取所有插件作业 这将返回插件所拥有的所有作业
Job[] allJobs =Job.getJobManager().find("Your_plugin_job_family_name");
希望这有帮助。
答案 1 :(得分:1)
您可以等待特定工作系列中的工作完成使用:
Job.getJobManager().join(jobFamily, progressMonitor);
答案 2 :(得分:0)
通过指定Job的系列创建作业,如下所示:
//create constant job family
final static String MY_JOB_FAMILY = "myPluginJob";
//Create Job
Job job = new Job("Job name") {
@Override
protected IStatus run(IProgressMonitor monitor) {
//perform the task
}
@Override
public boolean belongsTo(Object family) {
return family.equals(MY_JOB_FAMILY);
};
}
job.schedule();
在Activator.stop()中调用waitForJob(MY_JOB_FAMILY)
@Override
public void stop(BundleContext context) throws Exception {
waitForJob(MY_JOB_FAMILY);
//Do other shut down activities
}
public void waitForJob(String jobFamily) {
IJobManager jobManager = Job.getJobManager();
Job[] jobs = jobManager.find(jobFamily);
//Wait for all jobs belongs to family 'jobFamily'
while(jobs.length > 0) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
//Do nothing.
}
jobs = jobManager.find(jobFamily);
}
}
希望这会有所帮助。