Skip to main content

Mapping java threads to Win32 threads?

3 replies [Last post]
jeremygwa
Offline
Joined: 2006-01-17

Is it possible for a java thread to become, or to be identified as a native win32 thread on windows? My reason would be to be able manipulate the jvm threads via the win32 api, from an external process. Can this be done with Suns JVM?

Thanks in advance for your input.

-Jer A

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jeremygwa
Offline
Joined: 2006-01-17

how do I get the tid, or some way of identifying, that this is the thread I want to manipulate without jni?

briand
Offline
Joined: 2005-07-11

If you can send a CTRL-BREAK to the Java process, it will produce a thread dump on stdout. Each thread in this thread dump will have a "nid=" field which is the native thread id of the thread as returned by the windows GetCurrentThreadId() function. However, the ASCII output may be difficult to handle, particularly if stdout is redirected to some arbitrary file. Also, the technique is likely specific to the HotSpot JVM.

I'm not sure what you are trying to accomplish, but you might want to look at the JVMTI specification. It provides various information and operations for threads running in the JVM.

http://java.sun.com/j2se/1.5.0/docs/guide/jvmti/jvmti.html

HTH
Brian

briand
Offline
Joined: 2005-07-11

With the HotSpot JVM, all java threads map 1 to 1 to native operating system threads. How do you want to manipulate the threads?