Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #22361 > unrolled thread

JNI, threads are still running after DestroyJavaVM()

Started byOlivier GROSSET-GRANGE <olivier@clickndecide.eu>
First post2013-02-19 05:59 -0800
Last post2013-02-19 15:44 -0800
Articles 3 — 3 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  JNI, threads are still running after DestroyJavaVM() Olivier GROSSET-GRANGE <olivier@clickndecide.eu> - 2013-02-19 05:59 -0800
    Re: JNI, threads are still running after DestroyJavaVM() Arne Vajhoej <arne@vajhoej.dk> - 2013-02-19 12:44 -0500
      Re: JNI, threads are still running after DestroyJavaVM() olivier@clickndecide.eu - 2013-02-19 15:44 -0800

#22361 — JNI, threads are still running after DestroyJavaVM()

FromOlivier GROSSET-GRANGE <olivier@clickndecide.eu>
Date2013-02-19 05:59 -0800
SubjectJNI, threads are still running after DestroyJavaVM()
Message-ID<fa252d5a-78e9-42fb-8cfe-a7d737ec14f1@fv9g2000vbb.googlegroups.com>
Hello all,

As the object of this thread suggests, the problem I encounter is that
in a minimalist test program, there are "ghost" threads after calling
DestroyJavaVM().
The environment is WIN32, JRE/JDK 1.6.0_21, and C++ (Visual Studio
2008).
Under certain circumstances, it prevents some processes from exiting
(ie: IIS7.5 Application Pool : w3wp.exe).
May be I'm doing something wrong or I forgot one step,
Here is the very simple code to reproduce the problem:

// testDestroyJavaVM.cpp : Defines the entry point for the console
application.
//

#include "stdafx.h"

#include <conio.h>

#include "jni.h"
#pragma comment(lib, "jvm.lib")

int _tmain(int argc, _TCHAR* argv[])
{
	printf("press key to start");
	getch();
	printf("\nstart.");
	int MAX = 1; // can't call JNI_CreateJavaVM() more than once for some
reason...
	for (int i=0; i<MAX; i++)
	{
		JavaVM* jvm = NULL;
		JNIEnv* env = NULL;
		do
		{
			JavaVMOption jvmOptions;
			JavaVMInitArgs vm_args;
			vm_args.version = JNI_VERSION_1_6;
			vm_args.nOptions = 0;
			vm_args.options = &jvmOptions;
			vm_args.ignoreUnrecognized = 1;

			// *** 1 thread before JNI_CreateJavaVM() ***
			int retcode = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
			// *** 9 threads after JNI_CreateJavaVM() ***
			if(retcode < 0)
			{
				printf("JNI_CreateJavaVM failed: %d\n", retcode);
				break;
			}
		}
		while (false);
		if (NULL != jvm)
			jvm->DestroyJavaVM();
		// *** 6 threads after DestroyJavaVM() ***
	}
	printf("\ndone.");
	getch();
	return 0;
} // END OF CODE

Does someone know how to fix this problem please?
Is it a known problem ?

Thanks in advance for any help,
Olivier.

[toc] | [next] | [standalone]


#22367

FromArne Vajhoej <arne@vajhoej.dk>
Date2013-02-19 12:44 -0500
Message-ID<5123b9f0$0$292$14726298@news.sunsite.dk>
In reply to#22361
On 2/19/2013 8:59 AM, Olivier GROSSET-GRANGE wrote:
> As the object of this thread suggests, the problem I encounter is that
> in a minimalist test program, there are "ghost" threads after calling
> DestroyJavaVM().
> The environment is WIN32, JRE/JDK 1.6.0_21, and C++ (Visual Studio
> 2008).
> Under certain circumstances, it prevents some processes from exiting
> (ie: IIS7.5 Application Pool : w3wp.exe).
> May be I'm doing something wrong or I forgot one step,
> Here is the very simple code to reproduce the problem:

> 			JavaVMOption jvmOptions;
> 			JavaVMInitArgs vm_args;
> 			vm_args.version = JNI_VERSION_1_6;
> 			vm_args.nOptions = 0;
> 			vm_args.options = &jvmOptions;
> 			vm_args.ignoreUnrecognized = 1;
>
> 			// *** 1 thread before JNI_CreateJavaVM() ***
> 			int retcode = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
> 			// *** 9 threads after JNI_CreateJavaVM() ***

> 		if (NULL != jvm)
> 			jvm->DestroyJavaVM();
> 		// *** 6 threads after DestroyJavaVM() ***

> Does someone know how to fix this problem please?
> Is it a known problem ?

It is documented that non-daemon threads will continue to run
after DestroyJavaVM is called.

Do you actually start some Java code that is still running?

Other than that check the DestroyJavaVM method doc - I seem to
recall that it should be called with the jvm as argument.

Arne

[toc] | [prev] | [next] | [standalone]


#22379

Fromolivier@clickndecide.eu
Date2013-02-19 15:44 -0800
Message-ID<ae3bd0c6-d9c5-4f45-8125-3870146f0bf1@googlegroups.com>
In reply to#22367
Hello, 
Thanks for the answer.
No  java code is run in this example.
Fyi,the call to DestroyJavaVM is a c++ like call (which actually calls the riight JNI function with  jvm as  parameter).
Best regards,
Olivier

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web