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.