From b598909b6282d2d17609287d4f183271a5475849 Mon Sep 17 00:00:00 2001 From: "idk%eng.sun.com" Date: Fri, 6 Jul 2001 02:56:41 +0000 Subject: [PATCH] *not part of the build* fix for 88176 git-svn-id: svn://10.0.0.236/trunk@98775 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/java/xpcom/java/Makefile.in | 2 +- .../classes/org/mozilla/xpcom/Utilities.java | 2 +- .../java/jni/org_mozilla_xpcom_Components.cpp | 4 + mozilla/java/xpcom/java/src/bcIIDJava.cpp | 44 ++++++++--- mozilla/java/xpcom/java/src/bcJavaGlobal.cpp | 24 +++++- mozilla/java/xpcom/java/src/bcJavaGlobal.h | 3 +- mozilla/java/xpcom/java/src/bcJavaStub.cpp | 46 +++++++++++- .../xpcom/java/src/bcJavaStubsAndProxies.cpp | 75 +++++++++++++++++-- mozilla/java/xpcom/java/test/bcJavaSample.cpp | 40 +++++++++- .../java/xpcom/java/test/bcJavaSample.java | 8 +- 10 files changed, 220 insertions(+), 28 deletions(-) diff --git a/mozilla/java/xpcom/java/Makefile.in b/mozilla/java/xpcom/java/Makefile.in index ce8f0220a44..79cca865314 100644 --- a/mozilla/java/xpcom/java/Makefile.in +++ b/mozilla/java/xpcom/java/Makefile.in @@ -27,6 +27,6 @@ srcdir = @srcdir@ include $(DEPTH)/config/autoconf.mk -DIRS= xpidl src jni loader import classes components test +DIRS= xpidl src jni loader import classes components include $(topsrcdir)/config/rules.mk diff --git a/mozilla/java/xpcom/java/classes/org/mozilla/xpcom/Utilities.java b/mozilla/java/xpcom/java/classes/org/mozilla/xpcom/Utilities.java index 9b463201fdb..3cf8d3685d6 100644 --- a/mozilla/java/xpcom/java/classes/org/mozilla/xpcom/Utilities.java +++ b/mozilla/java/xpcom/java/classes/org/mozilla/xpcom/Utilities.java @@ -32,7 +32,7 @@ public class Utilities { Debug.log("--[java]callMethodByIndex args["+i+"] = "+args[i]); } Method method = InterfaceRegistry.getMethodByIndex(mid,iid); - Debug.log("--[java] org.mozilla.xpcom.Utilities.callMethodByIndex method "+method); + Debug.log("--[java] org.mozilla.xpcom.Utilities.callMethodByIndex method "+method+" object "+obj); try { if (method != null) { diff --git a/mozilla/java/xpcom/java/jni/org_mozilla_xpcom_Components.cpp b/mozilla/java/xpcom/java/jni/org_mozilla_xpcom_Components.cpp index 46f90d05981..1024ba1a207 100644 --- a/mozilla/java/xpcom/java/jni/org_mozilla_xpcom_Components.cpp +++ b/mozilla/java/xpcom/java/jni/org_mozilla_xpcom_Components.cpp @@ -44,13 +44,17 @@ JNIEXPORT void JNICALL Java_org_mozilla_xpcom_Components_initXPCOM nsIServiceManager* servMgr; rv = NS_InitXPCOM(&servMgr, NULL); if (NS_FAILED(rv)) { +#ifdef DEBUG_idk printf("--Components::initXPCOM failed \n"); +#endif return; } rv = nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup, NULL /* default */); if (NS_FAILED(rv)) { +#ifdef DEBUG_idk printf("--Components::initXPCOM failed \n"); +#endif return; } diff --git a/mozilla/java/xpcom/java/src/bcIIDJava.cpp b/mozilla/java/xpcom/java/src/bcIIDJava.cpp index 4a3c2375acd..850ad8aa434 100644 --- a/mozilla/java/xpcom/java/src/bcIIDJava.cpp +++ b/mozilla/java/xpcom/java/src/bcIIDJava.cpp @@ -29,41 +29,59 @@ jmethodID bcIIDJava::getStringMID = NULL; static nsID nullID = {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}}; void bcIIDJava::Init(void) { - JNIEnv * env = bcJavaGlobal::GetJNIEnv(); + int detachRequired; + JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired); if (env) { if (!(iidClass = env->FindClass("org/mozilla/xpcom/IID")) || !(iidClass = (jclass) env->NewGlobalRef(iidClass))) { env->ExceptionDescribe(); Destroy(); + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return; } if (!(iidInitMID = env->GetMethodID(iidClass,"","(Ljava/lang/String;)V"))) { env->ExceptionDescribe(); Destroy(); + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return; } if (!(getStringMID = env->GetMethodID(iidClass,"getString","()Ljava/lang/String;"))) { env->ExceptionDescribe(); Destroy(); + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return; } } } void bcIIDJava::Destroy() { - JNIEnv * env = bcJavaGlobal::GetJNIEnv(); + int detachRequired; + JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired); if (env) { - if (iidClass) { - env->DeleteGlobalRef(iidClass); - iidClass = NULL; - } + if (iidClass) { + env->DeleteGlobalRef(iidClass); + iidClass = NULL; + } + } + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); } } jobject bcIIDJava::GetObject(nsIID *iid) { - JNIEnv * env = bcJavaGlobal::GetJNIEnv(); + int detachRequired; + JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired); if (!iid || !env || nullID.Equals(*iid)) { + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return NULL; } if (!iidClass) { @@ -76,7 +94,11 @@ jobject bcIIDJava::GetObject(nsIID *iid) { siid[strlen(siid)-1] = 0; jstr = env->NewStringUTF((const char *)siid); } - return env->NewObject(iidClass,iidInitMID,jstr); + jobject ret = env->NewObject(iidClass,iidInitMID,jstr); + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } + return ret; } jclass bcIIDJava::GetClass() { @@ -85,7 +107,8 @@ jclass bcIIDJava::GetClass() { nsIID bcIIDJava::GetIID(jobject obj) { nsIID iid; - JNIEnv * env = bcJavaGlobal::GetJNIEnv(); + int detachRequired; + JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired); if (env) { if (!iidClass) { Init(); @@ -100,5 +123,8 @@ nsIID bcIIDJava::GetIID(jobject obj) { iid = nullID; } } + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return iid; } diff --git a/mozilla/java/xpcom/java/src/bcJavaGlobal.cpp b/mozilla/java/xpcom/java/src/bcJavaGlobal.cpp index 29fad3e17d8..af09d9fe43b 100644 --- a/mozilla/java/xpcom/java/src/bcJavaGlobal.cpp +++ b/mozilla/java/xpcom/java/src/bcJavaGlobal.cpp @@ -37,18 +37,38 @@ PRLogModuleInfo* bcJavaGlobal::log = NULL; #define JNIENV (void**) #endif -JNIEnv * bcJavaGlobal::GetJNIEnv(void) { +static int counter = 0; + +JNIEnv * bcJavaGlobal::GetJNIEnv(int *detachRequired) { JNIEnv * env; int res; + *detachRequired = 1; if (!jvm) { StartJVM(); } if (jvm) { - res = jvm->AttachCurrentThread(JNIENV &env,NULL); + res = jvm->GetEnv(JNIENV &env, JNI_VERSION_1_2); + if (res == JNI_OK) { + *detachRequired = 0; + } else { + res = jvm->AttachCurrentThread(JNIENV &env,NULL); +#ifdef DEBUG_idk + printf("--bcJavaGlobal::GetJNIEnv ++counter %d\n",++counter); +#endif + } } return env; } +void bcJavaGlobal::ReleaseJNIEnv() { + int res; + if (jvm) { + res = jvm->DetachCurrentThread(); +#ifdef DEBUG_idk + printf("--bcJavaGlobal::ReleaseJNIEnv --counter %d\n",--counter); +#endif + } +} void bcJavaGlobal::StartJVM() { PRLogModuleInfo * l = GetLog(); diff --git a/mozilla/java/xpcom/java/src/bcJavaGlobal.h b/mozilla/java/xpcom/java/src/bcJavaGlobal.h index a09d42aae8f..f40934cb84d 100644 --- a/mozilla/java/xpcom/java/src/bcJavaGlobal.h +++ b/mozilla/java/xpcom/java/src/bcJavaGlobal.h @@ -37,7 +37,8 @@ class bcJavaGlobal { public: - static JNIEnv * GetJNIEnv(void); + static JNIEnv * GetJNIEnv(int *detachRequired); + static void ReleaseJNIEnv(); static PRLogModuleInfo * GetLog(); private: static PRLogModuleInfo* log; diff --git a/mozilla/java/xpcom/java/src/bcJavaStub.cpp b/mozilla/java/xpcom/java/src/bcJavaStub.cpp index 4e598ae1ede..955f8190615 100644 --- a/mozilla/java/xpcom/java/src/bcJavaStub.cpp +++ b/mozilla/java/xpcom/java/src/bcJavaStub.cpp @@ -41,17 +41,26 @@ bcJavaStub::bcJavaStub(jobject obj) : orb(NULL) { PR_LOG(log,PR_LOG_DEBUG,("--bcJavaStub::bcJavaStub obj== 0\n")); return; } - JNIEnv * env = bcJavaGlobal::GetJNIEnv(); + int detachRequired; + JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired); object = env->NewGlobalRef(obj); refCounter = 0; + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } } bcJavaStub::~bcJavaStub() { - bcJavaGlobal::GetJNIEnv()->DeleteGlobalRef(object); + int detachRequired; + JNIEnv *env = bcJavaGlobal::GetJNIEnv(&detachRequired); + env->DeleteGlobalRef(object); if (orb != NULL) { orb->UnregisterStub(oid); } + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } } @@ -66,13 +75,17 @@ void bcJavaStub::SetOID(bcOID _oid) { void bcJavaStub::Dispatch(bcICall *call) { //sigsend(P_PID, getpid(),SIGINT); PRLogModuleInfo *log = bcJavaGlobal::GetLog(); - JNIEnv * env = bcJavaGlobal::GetJNIEnv(); + int detachRequired; + JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired); bcIID iid; bcOID oid; bcMID mid; jobjectArray args; call->GetParams(&iid, &oid, &mid); if (mid == 1) { //AddRef refCounter++; + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return; } else if (mid == 2) { //Release refCounter--; @@ -80,6 +93,9 @@ void bcJavaStub::Dispatch(bcICall *call) { if (refCounter <= 0) { printf("-java delete\n"); delete this; + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return; } } @@ -88,15 +104,24 @@ void bcJavaStub::Dispatch(bcICall *call) { nsIInterfaceInfoManager* iimgr; if((iimgr = XPTI_GetInterfaceInfoManager()) != NULL) { if (NS_FAILED(iimgr->GetInfoForIID(&iid, &interfaceInfo))) { + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return; //nb exception handling } NS_RELEASE(iimgr); } else { + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return; } if (!objectClass) { Init(); if (!objectClass) { + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return; } } @@ -124,26 +149,39 @@ void bcJavaStub::Dispatch(bcICall *call) { mt->Marshal(m, retval); } delete m; delete um; delete mt; + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return; } void bcJavaStub::Init() { - JNIEnv * env = bcJavaGlobal::GetJNIEnv(); + int detachRequired; + JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired); objectClass = (jclass)env->NewGlobalRef(env->FindClass("java/lang/Object")); if (env->ExceptionOccurred()) { env->ExceptionDescribe(); + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return; } utilitiesClass = (jclass)env->NewGlobalRef(env->FindClass("org/mozilla/xpcom/Utilities")); if (env->ExceptionOccurred()) { env->ExceptionDescribe(); + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return; } callMethodByIndexMID = env->GetStaticMethodID(utilitiesClass,"callMethodByIndex","(Ljava/lang/Object;Lorg/mozilla/xpcom/IID;I[Ljava/lang/Object;)Ljava/lang/Object;"); if (env->ExceptionOccurred()) { env->ExceptionDescribe(); + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return; } } diff --git a/mozilla/java/xpcom/java/src/bcJavaStubsAndProxies.cpp b/mozilla/java/xpcom/java/src/bcJavaStubsAndProxies.cpp index 353d9364dcd..813f2ed51f1 100644 --- a/mozilla/java/xpcom/java/src/bcJavaStubsAndProxies.cpp +++ b/mozilla/java/xpcom/java/src/bcJavaStubsAndProxies.cpp @@ -118,10 +118,14 @@ NS_IMETHODIMP bcJavaStubsAndProxies::GetProxy(bcOID oid, const nsIID &iid, bcIOR *proxy = (jobject)tmp; PR_LOG(log, PR_LOG_DEBUG, ("\n--bcJavaStubsAndProxies::GetProxy we have shortcut for oid=%d\n",oid)); } else { - JNIEnv * env = bcJavaGlobal::GetJNIEnv(); + int detachRequired; + JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired); jobject jiid = bcIIDJava::GetObject((nsIID*)&iid); *proxy = env->CallStaticObjectMethod(proxyFactory,getProxyID, (jlong)oid, jiid, (jlong)orb); EXCEPTION_CHECKING(env); + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } } return NS_OK; } @@ -135,16 +139,21 @@ NS_IMETHODIMP bcJavaStubsAndProxies::GetInterface(const nsIID &iid, jclass *cla if (!componentLoader) { return NS_ERROR_FAILURE; } - JNIEnv * env = bcJavaGlobal::GetJNIEnv(); + int detachRequired; + JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired); jobject jiid = bcIIDJava::GetObject((nsIID*)&iid); *clazz = (jclass)env->CallStaticObjectMethod(proxyFactory,getInterfaceID, jiid); + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return NS_OK; } NS_IMETHODIMP bcJavaStubsAndProxies::GetOID(jobject object, bcIORB *orb, bcOID *oid) { PRLogModuleInfo *log = bcJavaGlobal::GetLog(); nsresult rv = NS_OK; - JNIEnv * env = bcJavaGlobal::GetJNIEnv(); + int detachRequired; + JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired); if (env->IsInstanceOf(object,java_lang_reflect_Proxy)) { EXCEPTION_CHECKING(env); jobject handler = env->CallStaticObjectMethod(java_lang_reflect_Proxy,getInvocationHandlerID,object); @@ -154,12 +163,18 @@ NS_IMETHODIMP bcJavaStubsAndProxies::GetOID(jobject object, bcIORB *orb, bcOID EXCEPTION_CHECKING(env); *oid = env->CallLongMethod(handler,getOIDID); PR_LOG(log, PR_LOG_DEBUG, ("--bcJavaStubsAndProxies::GetOID we are using old oid %d\n",*oid)); + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return rv; } } bcIStub *stub = new bcJavaStub(object); *oid = orb->RegisterStub(stub); oid2objectMap->Put(new bcOIDKey(*oid),object); + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return rv; } @@ -167,13 +182,17 @@ NS_IMETHODIMP bcJavaStubsAndProxies::GetOID(jobject object, bcIORB *orb, bcOID NS_IMETHODIMP bcJavaStubsAndProxies::GetOID(char *location, bcOID *oid) { PRLogModuleInfo *log = bcJavaGlobal::GetLog(); PR_LOG(log,PR_LOG_DEBUG,("--bcJavaStubsAndProxies::GetOID %s\n",location)); - JNIEnv * env = bcJavaGlobal::GetJNIEnv(); + int detachRequired; + JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired); nsresult result; if (!componentLoader) { Init(); } if (!componentLoader) { + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return NS_ERROR_FAILURE; } //location[strlen(location)-5] = 0; //nb dirty hack. location is xyz.jar.info @@ -184,59 +203,87 @@ NS_IMETHODIMP bcJavaStubsAndProxies::GetOID(char *location, bcOID *oid) { NS_WITH_SERVICE(bcIORBComponent,_orb,kORBComponent,&result); if (NS_FAILED(result)) { PR_LOG(log,PR_LOG_DEBUG,("--bcJavaStubsAndProxies::GetOID failed\n")); + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return result; } bcIORB *orb; _orb->GetORB(&orb); *oid = orb->RegisterStub(stub); + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return NS_OK; } void bcJavaStubsAndProxies::Init(void) { PRLogModuleInfo *log = bcJavaGlobal::GetLog(); PR_LOG(log, PR_LOG_DEBUG,("--[c++]bcJavaStubsAndProxies::Init\n")); - JNIEnv * env = bcJavaGlobal::GetJNIEnv(); + int detachRequired; + JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired); componentLoader = env->FindClass("org/mozilla/xpcom/ComponentLoader"); if (env->ExceptionOccurred()) { env->ExceptionDescribe(); componentLoader = 0; PR_LOG(log,PR_LOG_ALWAYS,("--Did you set CLASSPATH correctly\n")); + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return; } componentLoader = (jclass)env->NewGlobalRef(componentLoader); if (env->ExceptionOccurred()) { env->ExceptionDescribe(); componentLoader = 0; + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return; } loadComponentID = env->GetStaticMethodID(componentLoader,"loadComponent","(Ljava/lang/String;)Ljava/lang/Object;"); if (env->ExceptionOccurred()) { env->ExceptionDescribe(); componentLoader = 0; + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return; } proxyFactory = env->FindClass("org/mozilla/xpcom/ProxyFactory"); if (env->ExceptionOccurred()) { env->ExceptionDescribe(); componentLoader = 0; + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return; } proxyFactory = (jclass)env->NewGlobalRef(proxyFactory); if (env->ExceptionOccurred()) { env->ExceptionDescribe(); componentLoader = 0; + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return; } getProxyID = env->GetStaticMethodID(proxyFactory, "getProxy","(JLorg/mozilla/xpcom/IID;J)Ljava/lang/Object;"); if (env->ExceptionOccurred()) { env->ExceptionDescribe(); componentLoader = 0; + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return; } getInterfaceID = env->GetStaticMethodID(proxyFactory, "getInterface","(Lorg/mozilla/xpcom/IID;)Ljava/lang/Class;"); if (env->ExceptionOccurred()) { env->ExceptionDescribe(); componentLoader = 0; + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return; } @@ -244,6 +291,9 @@ void bcJavaStubsAndProxies::Init(void) { if (env->ExceptionOccurred()) { env->ExceptionDescribe(); componentLoader = 0; + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return; } @@ -253,6 +303,9 @@ void bcJavaStubsAndProxies::Init(void) { if (env->ExceptionOccurred()) { env->ExceptionDescribe(); componentLoader = 0; + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return; } @@ -260,6 +313,9 @@ void bcJavaStubsAndProxies::Init(void) { if (env->ExceptionOccurred()) { env->ExceptionDescribe(); componentLoader = 0; + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return; } @@ -267,12 +323,18 @@ void bcJavaStubsAndProxies::Init(void) { if (env->ExceptionOccurred()) { env->ExceptionDescribe(); componentLoader = 0; + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return; } org_mozilla_xpcom_ProxyHandler = (jclass)env->NewGlobalRef(org_mozilla_xpcom_ProxyHandler); if (env->ExceptionOccurred()) { env->ExceptionDescribe(); componentLoader = 0; + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return; } @@ -280,6 +342,9 @@ void bcJavaStubsAndProxies::Init(void) { if (env->ExceptionOccurred()) { env->ExceptionDescribe(); componentLoader = 0; + if (detachRequired) { + bcJavaGlobal::ReleaseJNIEnv(); + } return; } diff --git a/mozilla/java/xpcom/java/test/bcJavaSample.cpp b/mozilla/java/xpcom/java/test/bcJavaSample.cpp index dff5f038fed..f676dfdbc5e 100644 --- a/mozilla/java/xpcom/java/test/bcJavaSample.cpp +++ b/mozilla/java/xpcom/java/test/bcJavaSample.cpp @@ -25,6 +25,8 @@ #include "nsIModule.h" #include "nsIEnumerator.h" #include "stdlib.h" +#include "prthread.h" +#include "prmon.h" #define BC_JAVA_SAMPLE_CID \ {0x072fa586, 0x1dd2, 0x11b2, \ @@ -132,6 +134,26 @@ NS_IMETHODIMP bcJavaSample::Test9(nsIID * *po) { return NS_OK; } + +static bcIJavaSample * javaSample = NULL; + +void thread_start( void *arg ) { + printf("--thread_start currentThread=%p\n",PR_GetCurrentThread()); + if (javaSample == NULL) { + nsresult r; + r = nsComponentManager::CreateInstance("bcJavaSample", + nsnull, + NS_GET_IID(bcIJavaSample), + (void**)&javaSample); + // } else { + bcIJavaSample *t; + javaSample->Test1((int)PR_GetCurrentThread()); + printf("--thread_start after first invocation \n"); + javaSample->Test1((int)PR_GetCurrentThread()); + printf("--thread_start after second invocation \n"); + } +} + void test() { printf("--BlackConnect test start\n"); nsresult r; @@ -148,17 +170,31 @@ void test() { //sigsend(P_PID, getpid(),SIGINT); //test->Test1(2000); #if 1 + { + for (int i = 0; i < 1; i++) { + printf("\n--we are creating threads i=%d\n",i); + PRThread *thr = PR_CreateThread( PR_USER_THREAD, + thread_start, + test, + PR_PRIORITY_NORMAL, + PR_LOCAL_THREAD, + PR_JOINABLE_THREAD, + 0); + PR_JoinThread(thr); + } + } + return; +#endif test->Test1(1000); bcIJavaSample *test1; if (NS_FAILED(r)) { printf("failed to get component. try to restart test\n"); } else { test->Test2(a); - } + } test->QueryInterface(NS_GET_IID(bcIJavaSample),(void**)&test1); int intArray[] = {1,2,3}; test->Test3(3, intArray); -#endif { char ** valueArray = (char **)malloc(sizeof(char*)*4); valueArray[0] = "hi"; diff --git a/mozilla/java/xpcom/java/test/bcJavaSample.java b/mozilla/java/xpcom/java/test/bcJavaSample.java index 92d9aae074b..17f8d0f1701 100644 --- a/mozilla/java/xpcom/java/test/bcJavaSample.java +++ b/mozilla/java/xpcom/java/test/bcJavaSample.java @@ -48,9 +48,11 @@ public class bcJavaSample implements bcIJavaSample { } public void test1(int l) { System.out.println("--[java]bcJavaSample.test1 "+l+"\n"); - - - } + try { + Thread.currentThread().sleep(1000); + } catch (java.lang.InterruptedException e) { + }; + } public void test2(bcIJavaSample o) { System.out.println("--[java]bcJavaSample.test2"); System.out.println("--[java]bcJavaSample.test2 :)))) Hi there");