Reputation: 2148
I have a library call, let's say Descriptor.compute(Molecule m)
.
This call hangs forever for some molecules (a bug in the library) and for some molecules, it does the computation for a long time. I want to run the computation on server, preferably in multi-threaded or multi-processed way so that all processors can be used. Also, I don't want the computer to spend more time than TIMEOUT
on any molecule.
Because the compute
method doesn't do any checking of isInterrupted()
nor waits anywhere, it doesn't respond to Thread.interrupt()
call.
So I think I need to use Thread.stop()
which works fine in stopping this type of task.
My question is: Is there some Thread pool which is capable of actually stopping the threads?
I made a simple pool which uses ArrayBlockingQueue<Input>
and ArrayBlockingQueue<Result>
for communication. However, I'm getting strange NullPointerException
s during the compute()
which I'm unable to trace (these exceptions have also null stack trace). So I'm asking if there already isn't some existing implementation, my googling didn't bring any fruit, everything I've found only interrupt
s.
Thank you for your time.
EDIT: By the way, the library is CDK.
Upvotes: 0
Views: 200
Reputation: 262814
There is no good way in Java to "kill" a thread. Read the long disclaimer on the deprecated Thread#stop method. Because of that, no modern API (such as ExecutorServices in the JDK) will make use of this method.
You have to make those threads check for interrupts and termination flags.
Upvotes: 2