Nat Luengnaruemitchai

Geek Blog

  Home  |   Contact  |   Syndication    |   Login
  100 Posts | 0 Stories | 230 Comments | 236 Trackbacks

News

Archives

Post Categories

Blogroll

Yesterday, I came across a problem where I host JVM inside a process and use JNI to connect to JVM. Usually it should work fine. However, when you spin off a new thread from unmanaged world and make a JNI call into Java code that uses ClassLoader. That's where I ran into the problem. Since the thread is instantiated outside JVM, therefore, Thread.currentThread().getContextClassLoader() is not set properly. It would be defaulted to System/Bootstrap ClassLoader instead. Therefore, it cannot find the class it has to load.

To solve this problem, I kept a reference of ClassLoader which I got from Thread.currentThread().getContextClassLoader() and set it to the new thread I created before making a call into Java code.

posted on Friday, August 26, 2005 4:45 AM