[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform] Re: how to control job worker thread
|
I worked out a solution by writing a special thread class that manages incoming jobs in a blocking FiFo queue
(java.util.concurrent.ArrayBlockingQueue). The workload is queued in this thread and all engine calls are thus made from
this thread instead of the job API's worker thread.
I wrapped the engine instance in a ThreadLocal variable just to be safe, although a simple instance variable would
probably suffice in my case...
All in all, the job API is great, but it was a bit confusing at first, because there is a "setThread()" method for jobs,
that does NOT do what I and probably others expect it to do. I'd like the API give the user more control over the
threads actually used by some jobs. For instance, I would really like to specify that all jobs of the same family should
run in the same thread. That would've helped me alot and I wouldn't have had to write my own "pool" with all
thread-safety issues involved AGAIN.
Norbert Schöpke wrote:
> Hi
>
> Is there any way to use the Eclipse job API and force it always uses the same worker thread, or a thread of my choosing?
>
> To explain my problem:
> I'm having trouble with my eclipse jobs, as I need to make sure, they're all run on a specific thread, or at least
> always on the same thread.
>
> Why do I need this?
> Well I use JNA to access a native application. The access is actually implemented by a 3rd-party project. Using this
> projects API I create an instance of an "Engine" object in my code, that uses JNA to act as a facade to the native
> application (its a numerical engine called "Matlab"). I use this to do expensive computations, so I really, really HAVE
> to do it with a job or separate thread of my own.
>
> The problem is that I can only work with this JNA engine instance from the same thread where it was created.
> Following the tutorial "On the Job" and other documentation I use jobs when accessing this engine.
> Eclipse assigns different worker threads to my jobs (at will, as its probably supposed to do).
> Right now I have little control over the 3rd-party code. It is open source, but I don't understand JNA well enough to
> fix it (I already contacted the author though). So even if it is a bug on behalf of this project, I probably have to
> work around it on my side.
>
> To repeat the question:
> Is there any way to use the Eclipse job API and force it always uses the same worker thread, or a thread of my choosing?
> Or: Is there another way to spawn background processes with a nice Eclipse progress dialog and job completion
> notification that doesn't use this random worker pool?
>
> Thx very much for any ideas
> Norbert Schoepke