Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to complete a Job when user closes Eclipse application

Tags:

java

eclipse

jobs

I use org.eclipse.core.runtime.jobs.Job to execute stored procedure which deletes data and to update user interface according to the new data. Thus it is important that this job will be completed even if user closes eclipse application.

final Job execStoredProcJob = new Job(taskName) {
    protected IStatus run(IProgressMonitor monitor) {
        monitor.beginTask(taskName, 
// execute stored procedure
// update user interface
        monitor.done();
        return Status.OK_STATUS;
    }
};

execStoredProcJob.schedule();

When I close eclipse app while the Job still running it seems to kill the Job. How to complete the job after user has closed eclipse app? Is it possible?

like image 604
ka3ak Avatar asked Nov 14 '22 11:11

ka3ak


1 Answers

I think you might want to take a look at scheduling rules http://www.eclipse.org/articles/Article-Concurrency/jobs-api.html

execStoredProcJob.setRule([Workspace root]);
execStoredProcJob.schedule();

[Workspace root] can be attained like project.getWorkspace().getRoot() if you have a reference to your project.

That will block all jobs that require the same rule. The shutdown job is one of them..

It's also possible to:

IWorkspace myWorkspace = org.eclipse.core.resources.ResourcesPlugin.getWorkspace();

Then use:

myWorkspace.getRoot();
like image 173
Enrico Avatar answered Nov 16 '22 02:11

Enrico