简体   繁体   中英

Run a thread always in eclipse

I am writing an eclipse plugin which will always check the file in current active editor (if editor changes, then it will check new editor) and then highlight some lines in the editor. (A database contains all file names and associated lines that need to be highlighted).

I was succeed to develop the plugin. The problem is, it only checks the database once and produce my own error message if it can't connect to database. I want the plugin to check the database regularly (for new updates) and as soon as its connected to database, it will highlight the editor immediately.

I think I can't use a eclipse WorkspaceJob for it because workspaceJob will check the editor only one time, but I want to keep it as a continuous process in a certain interval (say every 30 seconds). So, I think a thread is suitable.

But how can I implement it? How can I run a thread in eclipse, that will run always? Is there any better solution?

You can still use a WorkspaceJob with the schedule(long delay) method to set your 30 second delay. Have the job reschedule itself after it has run to get it to run on a regular basis:

WorkspaceJob job = new WorkspaceJob("jobname") {
    @Override
    public IStatus runInWorkspace(IProgressMonitor monitor)
            throws CoreException {
        // TODO add code here
        this.schedule(30000);
        return Status.OK_STATUS;
    }
};
job.schedule();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM