Another fix for the JVM hanging on exit problem when using directors
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10550 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
3463ced917
commit
a1590359c9
3 changed files with 21 additions and 2 deletions
|
|
@ -1,6 +1,11 @@
|
|||
Version 1.3.36 (in progress)
|
||||
=============================
|
||||
|
||||
06/22/2008: wsfulton
|
||||
[Java] Add a way to use AttachCurrentThreadAsDaemon instead of AttachCurrentThread
|
||||
in director code. Define the SWIG_JAVA_ATTACH_CURRENT_THREAD_AS_DAEMON macro, see
|
||||
Lib/java/director.swg.
|
||||
|
||||
06/21/2008: wsfulton
|
||||
[Ruby] Fix crashing in the STL wrappers (reject! and delete_if methods)
|
||||
|
||||
|
|
|
|||
|
|
@ -3450,6 +3450,14 @@ DirectorDerived::upcall_method() invoked.
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<H3><a name="java_directors_threading"></a>Director threading issues</H3>
|
||||
|
||||
<p>
|
||||
Depending on your operating system and version of Java and how you are using threads, you might find the JVM hangs on exit.
|
||||
There are a couple of solutions to try out. The preferred solution requires jdk-1.4 and later and uses <tt>AttachCurrentThreadAsDaemon</tt> instead of <tt>AttachCurrentThread</tt> whenever a call into the JVM is required. This can be enabled by defining the SWIG_JAVA_ATTACH_CURRENT_THREAD_AS_DAEMON macro when compiling the C++ wrapper code. For older JVMs define SWIG_JAVA_NO_DETACH_CURRENT_THREAD instead, to avoid the <tt>DetachCurrentThread</tt> call but this will result in a memory leak instead. For further details inspect the source code in the java/director.swg library file.
|
||||
</p>
|
||||
|
||||
|
||||
<H2><a name="java_allprotected"></a>20.6 Accessing protected members</H2>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -117,12 +117,18 @@ namespace Swig {
|
|||
JNIEnv *jenv_;
|
||||
public:
|
||||
JNIEnvWrapper(const Director *director) : director_(director), jenv_(0) {
|
||||
#if defined(SWIG_JAVA_ATTACH_CURRENT_THREAD_AS_DAEMON)
|
||||
// Attach a daemon thread to the JVM. Useful when the JVM should not wait for
|
||||
// the thread to exit upon shutdown. Only for jdk-1.4 and later.
|
||||
director_->swig_jvm_->AttachCurrentThreadAsDaemon((void **) &jenv_, NULL);
|
||||
#else
|
||||
director_->swig_jvm_->AttachCurrentThread((void **) &jenv_, NULL);
|
||||
#endif
|
||||
}
|
||||
~JNIEnvWrapper() {
|
||||
// Some JVMs, eg JDK 1.4.2 and lower on Solaris have a bug and crash with the DetachCurrentThread call.
|
||||
// However, without this call, the JVM hangs on exit when the thread was not created by the JVM and creates a memory leak.
|
||||
#if !defined(SWIG_JAVA_NO_DETACH_CURRENT_THREAD)
|
||||
// Some JVMs, eg jdk-1.4.2 and lower on Solaris have a bug and crash with the DetachCurrentThread call.
|
||||
// However, without this call, the JVM hangs on exit when the thread was not created by the JVM and creates a memory leak.
|
||||
director_->swig_jvm_->DetachCurrentThread();
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue