Saturday, October 5, 2013

How do you start a new thread from plugin start() method upon plugin active.

We can call below particular snippet from any plugin start() method. 

final Bundle currentBundle = getBundle();
Job serviceJob = new Job("services starting...") {
@Override
protected IStatus run(IProgressMonitor monitor) {
while (currentBundle.getState() != Bundle.ACTIVE) {
try {
Thread.sleep(1000); //wait for some time and then re-check
} catch (InterruptedException e) {
e.printStackTrace();
}
}

startService();  //service implemenation goes here - this what you wanted to do after plugin is active

return Status.OK_STATUS;
}
};
serviceJob.schedule();

No comments:

Post a Comment