0
我正在學習Eclipse作業API,但找不到有關如何使用系列類的示例的任何文檔。我正在努力創造3個工作,其中前兩個屬於同一個家庭,另外一個屬於不同的家庭。我無法創造出可以提及某個特定家庭的工作。瞭解Eclipse作業系列
代碼下面給出: 第一個文件含有工作描述預先
public class Jobsclass{
public static void eclipsejobsfamily() {
Job MyFirstJob = new Job("My First Job") {
protected IStatus run(IProgressMonitor monitor) {
System.out.println("Hello World (1st from a background First job)");
return Status.OK_STATUS;
}
public boolean belongsTo(Object family) {
// TODO Auto-generated method stub
if (Jobsutil.MY_FAMILY.equals(family)) { return true; }
return false;
}
};
Job MySecondJob = new Job("My Second Job") {
protected IStatus run(IProgressMonitor monitor) {
System.out.println("Hello World (2nd from a background Second job)");
return Status.OK_STATUS;
}
public boolean belongsTo(Object family) {
// TODO Auto-generated method stub
if (Jobsutil.MY_FAMILY.equals(family)) { return true; }
return false;
}
};
Job MyThirdJob = new Job("My First Job") {
protected IStatus run(IProgressMonitor monitor) {
System.out.println("Hello World (1st from a background First job)");
return Status.OK_STATUS;
}
public boolean belongsTo(Object family) {
// TODO Auto-generated method stub
if (Jobsutil.THE_FAMILY.equals(family)) { return true; }
return false;
}
};
MyFirstJob.wakeUp();
MyFirstJob.schedule();
MySecondJob.setPriority(Job.SHORT);
MySecondJob.schedule();
MyThirdJob.wakeUp();
MyThirdJob.schedule();
}
protected IStatus run(IProgressMonitor monitor) {
// TODO Auto-generated method stub
return null;
}
}
FILE 2:
public class Jobsutil {
public static final String MY_FAMILY = "myJobFamily";
public static final String THE_FAMILY = "theOtherFamily";
}
public JobAction() {
}
THIRD Class Method RUN():
/**
* The action has been activated. The argument of the
* method represents the 'real' action sitting
* in the workbench UI.
* @see IWorkbenchWindowActionDelegate#run
*/
public void run(IAction action) {
MessageDialog.openInformation(
window.getShell(),
"LearnJobAPI",
"First example");
if (Jobsutil.MY_FAMILY.equals("myJobFamily")){
}
//Job.getJobManager().find("MY_FAMILY");
//Job.getJobManager().wakeUp("MY_FAMILY");
// Jobsclass.eclipsejobsfamily();
this.manager.wakeUp(Jobsutil.MY_FAMILY);
Job[] jobscreated= this.manager.find(Jobsutil.MY_FAMILY);
Jobsclass.eclipsejobsfamily();
}
感謝。請幫助我瞭解如何使用家人控制工作。
感謝您的回答。嘗試後,我可以得到這個,但我無法得到。如何使用家庭「MY_FAMILY」運行這項工作。喜歡從家庭「A」運行作業或從家庭「B」運行作業。 –
添加了帶家庭參數的工作班 –
我能夠理解建議的代碼並實施它感謝您的幫助。但我的問題仍然在於我創建並預定了(家庭A,家庭B,家庭B)的3個職位。我如何才能運行只屬於家庭B的作業。我創建了這樣的東西,但它不工作:私人IJobManager經理= Platform.getJobManager();和manager.wakeUp(「B」);這種方法好嗎或請建議。非常感謝 –