Re: Suspending and resuming JNI thread
Thanku for explain.. but still i am not able to control....
I am calling the Native thread through start button by calling
mynative.thread.start();
C code also altered according to ur suggestion..
i am creating one more instance of Suspend at GUI class.. and
for wait i am calling the susp.wait() for suspend click... but it is
not responding... i am requesting u to please look my code of GUI and
Mynative class in my previous post...
one more question is...
here we are keep on checking in while (C code)... if the
program calling a one more c function(very lengthy)
ex,..
JNIEXPORT void JNICALL Java_Mynative_Cfun(JNIEnv *env1, jobject
objj, jobject susp)
{
a();
}
a()
{
.....
....
}
then how can i rewrite the C code or java code inorder to suspend
and resume , stop click work ..
Thanking u once again,
Ganesh.
Gordon Beaton wrote:
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