Re: Suspending and resuming JNI thread
On 30 Nov 2006 05:01:10 -0800, ganeshamutha@gmail.com wrote:
Please explain me .. how i have to change the code inorder to make
working of suspend, resume and stop with ur code...
Create an instance of the Suspend class I posted earlier. Pass the
reference as an argument to your C function (you'll need to change the
native declaration and re-run javah).
Now change your C function, so that it occasionally invokes
susp.wait_here():
JNIEXPORT void JNICALL Java_Mynative_Cfun(JNIEnv *env1, jobject objj, jobject susp)
{
jclass cls = (*env)->GetObjectClass(env1, susp);
jmethodID mid = (*env)->GetMethodID(env1, cls, "wait_here", "()Z");
while (!(*env)->CallBooleanMethod(env1, susp, mid)) {
printf("C code...\n");
}
printf("Cancelled!\n");
return;
}
From elsewhere, call susp.suspend(), susp.resume(), or susp.cancel()
to control the native method.
/gordon
--
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e