diff options
author | Kay Ramme <kr@openoffice.org> | 2000-11-24 14:47:13 +0000 |
---|---|---|
committer | Kay Ramme <kr@openoffice.org> | 2000-11-24 14:47:13 +0000 |
commit | a8c94485fd4b590aab0d765cfb0f141251e6da79 (patch) | |
tree | 28d545c4c7c25151195254cdd0a7cee2fe241824 /javaunohelper/source | |
parent | 0ea6c1ec4558336e98449436cd9cafcc272842b6 (diff) |
reuse java environment if possible
Diffstat (limited to 'javaunohelper/source')
-rw-r--r-- | javaunohelper/source/javaunohelper.cxx | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/javaunohelper/source/javaunohelper.cxx b/javaunohelper/source/javaunohelper.cxx index 9bc59c4f0d77..46e7d8027e55 100644 --- a/javaunohelper/source/javaunohelper.cxx +++ b/javaunohelper/source/javaunohelper.cxx @@ -2,9 +2,9 @@ * * $RCSfile: javaunohelper.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: kr $ $Date: 2000-09-28 17:30:35 $ + * last change: $Author: kr $ $Date: 2000-11-24 15:47:12 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -373,11 +373,38 @@ extern "C" JNIEXPORT jobject JNICALL Java_com_sun_star_comp_helper_RegistryServi else rMSFac = createRegistryServiceFactory(aWriteRegFile, aReadRegFile, bReadOnly); - JavaVMContext * pVMContext = new JavaVMContext(pJVM); - pVMContext->registerThread(); - uno_getEnvironment(&pJavaEnv, OUString::createFromAscii("java").pData, pVMContext); - if(!pJavaEnv) throw RuntimeException(); + JavaVMContext * pVMContext = NULL; + + // possible race ? + { // get the java environment + uno_Environment ** ppEnviroments = NULL; + sal_Int32 size = 0; + OUString java(RTL_CONSTASCII_USTRINGPARAM("java")); + + uno_getRegisteredEnvironments(&ppEnviroments, &size, (uno_memAlloc)malloc, java.pData); + if(size) { // did we find an existing java environment? + OSL_TRACE("javaunohelper.cxx: RegistryServiceFactory.createRegistryServiceFactory: found an existing java environment"); + + pJavaEnv = ppEnviroments[0]; + pVMContext = (JavaVMContext *)pJavaEnv->pContext; + + for(sal_Int32 i = 1; i < size; ++ i) + ppEnviroments[i]->release(ppEnviroments[i]); + + free(ppEnviroments); + } + else { // no, create one + pVMContext = new JavaVMContext(pJVM); + + uno_getEnvironment(&pJavaEnv, java.pData, pVMContext); + if(!pJavaEnv) throw RuntimeException(); + } + } + + + + pVMContext->registerThread(); OUString aCurrentEnv(RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME)); uno_getEnvironment(&pCurrEnv, aCurrentEnv.pData, NULL); |