[jboss-svn-commits] JBL Code SVN: r9806 - labs/jbossweb/trunk/src/share/classes/org/apache/catalina/servlets/php.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Feb 27 03:40:47 EST 2007


Author: jfrederic.clere at jboss.com
Date: 2007-02-27 03:40:47 -0500 (Tue, 27 Feb 2007)
New Revision: 9806

Added:
   labs/jbossweb/trunk/src/share/classes/org/apache/catalina/servlets/php/PhpThread.java
Modified:
   labs/jbossweb/trunk/src/share/classes/org/apache/catalina/servlets/php/Library.java
Log:
Make sure that the startup and shutdown of php are made in the same thread overwise the JVM cores in php (on Linux for example but not on Solaris).


Modified: labs/jbossweb/trunk/src/share/classes/org/apache/catalina/servlets/php/Library.java
===================================================================
--- labs/jbossweb/trunk/src/share/classes/org/apache/catalina/servlets/php/Library.java	2007-02-27 07:28:44 UTC (rev 9805)
+++ labs/jbossweb/trunk/src/share/classes/org/apache/catalina/servlets/php/Library.java	2007-02-27 08:40:47 UTC (rev 9806)
@@ -1,5 +1,4 @@
 /*
-/*
  * JBoss, Home of Professional Open Source
  * Copyright 2006, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
@@ -41,6 +40,8 @@
     private static Library engine = null;
     private static boolean inited = false;
 
+    static PhpThread phpthread = null;
+
     private Library()
     {
         boolean loaded = false;
@@ -80,7 +81,7 @@
     /* Initialize PHP Engine
      * This has to be the first call to PHP Module.
      */
-    private static native boolean startup();
+    public static native boolean startup();
 
     /* destroy global PHP Engine
      * This has to be the last call to PHP Module.
@@ -107,7 +108,14 @@
             PHP_MINOR_VERSION  = version(2);
             PHP_PATCH_VERSION  = version(3);
         }
-        inited = startup();
+        
+        phpthread = new PhpThread();
+        phpthread.setDaemon(true);
+        phpthread.start();
+        // Wait until the startup is done.
+        while (!inited &&  phpthread.isAlive()) {
+            Thread.currentThread().sleep(3000);
+        }
         return inited;
     }
 
@@ -125,9 +133,14 @@
     public static void terminate()
     {
         if (engine != null) {
-            shutdown();
+            if (phpthread != null && phpthread.isAlive()) {
+                phpthread.interrupt();
+            }
             engine = null;
             inited = false;
         }
     }
+    public static void StartUp() {
+        inited = startup();
+    }
 }

Added: labs/jbossweb/trunk/src/share/classes/org/apache/catalina/servlets/php/PhpThread.java
===================================================================
--- labs/jbossweb/trunk/src/share/classes/org/apache/catalina/servlets/php/PhpThread.java	                        (rev 0)
+++ labs/jbossweb/trunk/src/share/classes/org/apache/catalina/servlets/php/PhpThread.java	2007-02-27 08:40:47 UTC (rev 9806)
@@ -0,0 +1,44 @@
+/*
+ *  Copyright(c) 2007 Red Hat Middleware, LLC,
+ *  and individual contributors as indicated by the @authors tag.
+ *  See the copyright.txt in the distribution for a
+ *  full listing of individual contributors.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library in the file COPYING.LIB;
+ *  if not, write to the Free Software Foundation, Inc.,
+ *  59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * @author Jean-Frederic Clere
+ * @version $Revision: 420067 $, $Date: 2006-07-08 09:16:58 +0200 (sub, 08 srp 2006) $
+ */
+package org.apache.catalina.servlets.php;
+
+import java.lang.Thread;
+import java.lang.InterruptedException;
+
+/* Thread that handle the php startup and shutdown */
+public class PhpThread extends Thread {
+    public void run() {
+        boolean ok = true;
+        Library.StartUp();
+        while (ok) {
+            try {
+                sleep(60000);
+            } catch (InterruptedException e) {
+                ok = false;
+            }
+        }
+        Library.shutdown();
+    }
+}




More information about the jboss-svn-commits mailing list