Java Daemon Threading with JNI
Posted
by
gwin003
on Stack Overflow
See other posts from Stack Overflow
or by gwin003
Published on 2013-06-24T16:18:06Z
Indexed on
2013/06/24
16:21 UTC
Read the original article
Hit count: 108
I have a Java applet that creates a new non-daemon thread like so:
Thread childThread = new Thread(new MyRunnable(_this));
childThread.setDaemon(false);
childThread.start();
Then my MyRunnable
object calls a native method that is implemented in C++:
@Override
public void run() {
while (true) {
if (!ran) {
System.out.println("isDaemon: " + Thread.currentThread().isDaemon());
_applet.invokePrintManager(_applet.fFormType,
_applet.fFormName, _applet.fPrintImmediately,
_applet.fDataSet);
ran = true;
}
}
}
This C++ method calls into a C# DLL that shows a form. My problem is, whenever the user navigates away from the page with a Java applet on it, JVM (and my C# form) is killed. I need the form and JVM to remain open until it is closed by the user. I tried setting my thread to be a non-daemon thread, which is working because System.out.println("isDaemon: " + Thread.currentThread().isDaemon()
prints isDaemon: false
.
Is there something related to the way that the C# form is created (is there another thread I'm not accounting for) or something I am overlooking?? My thread is not a daemon thread, but the JVM is being killed anyways.
© Stack Overflow or respective owner