executing asynchronous jobs (potentially long lived)

I see there is a JobScheduler in the OpenAPI, which allows both access to
- an implementation of java.util.concurrent.ScheduledExecutorService,
- an intellij JobScheduler abstraction

I need to start a long lived operation (should be running until the project is closed). I currently did it using raw use of Thread, and was wondering if I should change to one of the above ?

2 comments
Comment actions Permalink

If you want to switch, you most likely want to use com.intellij.openapi.application.Application#executeOnPooledThread. This was AFAIK created to eliminate the Thread-handle leak (on Windows) when creating many short-lived threads. If you've just got very few, long running threads, there might be no need to switch at all.

The JobScheduler API uses a thread pool that uses as many threads as there are CPU cores available - which you should not block by a rather long-running job. The "native" ScheduledExecutorService should, judging from the name of its Thread-factory, only be used for periodic tasks.

Sascha

0
Comment actions Permalink

thanks for the clarification, guess i'll stick with creating threads myself then

0

Please sign in to leave a comment.