The error lies in the native code that doesn't return, really. The only way to do it through the higher level java, as far as I know, is to stop()
the thread - which is deprecated for several reasons.
To do this, you'd need to redesign to use an old-fashioned Thread
instead of ExecutorService
. You might as well do that as the size is fixed at 1 and therefore ExecutorService
won't give you many advantages. As far as I see from your question it might seem like a viable option for you to use stop()
if you do not keep any locks in the thread when you stop()
it.
Edit:
According to Apple's developer guide (page 47), you can specify an EventTimeout
when calling ReceiveNextEvent
:
ReceiveNextEvent runs the low-level event loop, placing events as they
occur into the event queue. The function returns when an event you
specified occurs, or when the specified timeout is exceeded.
OSStatus ReceiveNextEvent(
UInt32 inNumTypes,
const EventTypeSpec *inList,
EventTimeout inTimeout,
Boolean inPullEvent,
EventRef *outEvent);
So, if I understand correctly setting a timeout when calling the native code will do the trick for you.