commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r909363 - in /commons/proper/daemon/trunk/src/native/nt/procrun: apps/prunsrv/prunsrv.c include/javajni.h src/javajni.c
Date Fri, 12 Feb 2010 11:28:35 GMT
Author: mturk
Date: Fri Feb 12 11:28:35 2010
New Revision: 909363

URL: http://svn.apache.org/viewvc?rev=909363&view=rev
Log:
Update fix for DAEMON-97 by making sure we don't block forewer if shutdown was executed

Modified:
    commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c
    commons/proper/daemon/trunk/src/native/nt/procrun/include/javajni.h
    commons/proper/daemon/trunk/src/native/nt/procrun/src/javajni.c

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c?rev=909363&r1=909362&r2=909363&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c Fri Feb 12 11:28:35
2010
@@ -39,6 +39,7 @@
 #define STDIN_FILENO  0
 #define STDOUT_FILENO 1
 #define STDERR_FILENO 2
+#define ONE_MINUTE    (60 * 1000)
 
 #ifdef WIN64
 #define KREG_WOW6432  KEY_WOW64_32KEY
@@ -1276,11 +1277,10 @@
 
         rv = apxHandleWait(gWorker, INFINITE, FALSE);
         apxLogWrite(APXLOG_MARK_DEBUG "Worker finished.");
-        reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
-        /* This will cause to wait for all threads to exit
-         * TODO: Use some kind of timeout wait logic
-         */
-        apxDestroyJvm();
+        if (gShutdownEvent) {
+        }
+        else
+            apxDestroyJvm(INFINITE);
         apxLogWrite(APXLOG_MARK_DEBUG "JVM destroyed.");
     }
     else {
@@ -1288,12 +1288,27 @@
         goto cleanup;
     }
     if (gShutdownEvent) {
+        reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
         /* Ensure that shutdown thread exits before us */
         apxLogWrite(APXLOG_MARK_DEBUG "Waiting for ShutdownEvent");
-        WaitForSingleObject(gShutdownEvent, 60 * 1000);
+        WaitForSingleObject(gShutdownEvent, ONE_MINUTE);
         apxLogWrite(APXLOG_MARK_DEBUG "ShutdownEvent signaled");
         CloseHandle(gShutdownEvent);
+        /* This will cause to wait for all threads to exit
+         */
+        apxLogWrite(APXLOG_MARK_DEBUG "Waiting 1 minute for all threads to exit");
+        apxDestroyJvm(ONE_MINUTE);
+    }
+    else {
+        /* We came here without shutdown event
+         * Probably because main() returned without ensuring all threads
+         * have finished
+         */
+        apxLogWrite(APXLOG_MARK_DEBUG "Waiting for all threads to exit");
+        apxDestroyJvm(INFINITE);
+        reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
     }
+    apxLogWrite(APXLOG_MARK_DEBUG "JVM destroyed.");
     reportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0);
 
     return;

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/include/javajni.h
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/include/javajni.h?rev=909363&r1=909362&r2=909363&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/include/javajni.h (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/include/javajni.h Fri Feb 12 11:28:35
2010
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
- 
+
 #ifndef _JAVAJNI_H_INCLUDED_
 #define _JAVAJNI_H_INCLUDED_
 
@@ -43,7 +43,7 @@
                           LPCWSTR szFilename);
 DWORD       apxJavaSetOptions(APXHANDLE hJava, DWORD dwOptions);
 
-BOOL        apxDestroyJvm(void);
+BOOL        apxDestroyJvm(DWORD dwTimeout);
 
 
 __APXEND_DECLS

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/src/javajni.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/src/javajni.c?rev=909363&r1=909362&r2=909363&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/src/javajni.c (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/src/javajni.c Fri Feb 12 11:28:35 2010
@@ -131,7 +131,7 @@
     jint _iStatus;
 
     if (!_st_sys_jvm)
-      return FALSE;  
+      return FALSE;
     _iStatus = (*(lpJava->lpJvm))->GetEnv(lpJava->lpJvm,
                                           (void **)&(lpJava->lpEnv),
                                           lpJava->iVersion);
@@ -151,7 +151,7 @@
 static __inline BOOL __apxJvmDetach(LPAPXJAVAVM lpJava)
 {
     if (!_st_sys_jvm)
-      return FALSE;  
+      return FALSE;
     if ((*(lpJava->lpJvm))->DetachCurrentThread(lpJava->lpJvm) != JNI_OK) {
         lpJava->lpEnv = NULL;
         return FALSE;
@@ -292,15 +292,34 @@
     return hJava;
 }
 
+static DWORD WINAPI __apxJavaDestroyThread(LPVOID lpParameter)
+{
+    JavaVM *lpJvm = (JavaVM *)lpParameter;
+    (*lpJvm)->DestroyJavaVM(lpJvm);
+    return 0;
+}
+
 BOOL
-apxDestroyJvm()
+apxDestroyJvm(DWORD dwTimeout)
 {
     if (_st_sys_jvm) {
+        DWORD  tid;
+        HANDLE hWaiter;
+        BOOL   rv = FALSE;
         JavaVM *lpJvm = _st_sys_jvm;
+
         _st_sys_jvm = NULL;
         (*lpJvm)->DetachCurrentThread(lpJvm);
-        (*lpJvm)->DestroyJavaVM(lpJvm);
-        return TRUE;
+        hWaiter = CreateThread(NULL, 0, __apxJavaDestroyThread,
+                               (void *)lpJvm, 0, &tid);
+        if (IS_INVALID_HANDLE(hWaiter)) {
+            apxLogWrite(APXLOG_MARK_SYSERR);
+            return FALSE;
+        }
+        if (WaitForSingleObject(hWaiter, dwTimeout) == WAIT_OBJECT_0)
+            rv = TRUE;
+        CloseHandle(hWaiter);
+        return rv;
     }
     else
         return FALSE;



Mime
View raw message