Java – how to complete a job when a user closes an eclipse application

I use org eclipse. core. runtime. jobs. Job executes stored procedures, deletes data and updates the user interface based on the new data Therefore, this work is important even if the user closes the 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 closed the eclipse application, the job was still running, and it seemed to kill the job How do users complete their work after they close the eclipse application? Is it possible?

Solution

I think you might want to see the scheduling rules

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

If you have a reference to a project, you can like project getWorkspace(). Implement [workspace root] as getroot()

This will block all jobs that require the same rule Shutdown is one of them

It may also:

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

Then use:

myWorkspace.getRoot();
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>