JNI Trouble calling FindClass from Worker thread



Hello
I am able to get the class object when i call FindClass in the main
thread. Now when i spawn a worker thread and attempt the same call
after caching the JVM and creating a new Env . it fails and triggers an
exception on the Java side .


My code for a DLL looks like this

JMVM *jvm = NULL ;

...
DLLMain()
{
}

JNIEXPORT jint JNICALL Initialize
(JNIEnv *pEnv, jclass)
{

pEnv->GetJavaVM(&jvm);
ASSERT(jvm!=NULL);

jclass cls = pEnv->FindClass("demoflashplugin/views/Objfactory");

if(cls!=NULL)
AfxMessageBox("cls found");


AfxBeginThread(WindowThread , NULL);

}



UINT WindowThread(LPVOID p)
{

JNIEnv *env = NULL ;
jclass cclass ;
if(jvm!=NULL)
{
if (0==jvm->AttachCurrentThread((void**)&env,NULL))
{
if ((env)->ExceptionOccurred()) {
AfxMessageBox("Exception occured");
(env)->ExceptionDescribe() ;
}
if(env!=NULL)
{
AxMessageBox(getenv("CLASSPATH"));
cclass = env->FindClass(demoflashplugin/views/Objfactory");
if(cclass!=NULL)
{
AfxMessageBox("Class is not Null");
}
else
AfxMessageBox("Class is s Null");
}
else
{
AfxMessageBox("env is NULL ");
}

AfxMessageBox("Finished checking for string");
}
else
{
AfxMessageBox("JVM IS Null");
}


}
}

.