cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From giac...@apache.org
Subject svn commit: rev 56765 - in cocoon/trunk/src: java/org/apache/cocoon/components/thread webapp/WEB-INF
Date Sat, 06 Nov 2004 13:54:32 GMT
Author: giacomo
Date: Sat Nov  6 05:54:31 2004
New Revision: 56765

Modified:
   cocoon/trunk/src/java/org/apache/cocoon/components/thread/DefaultRunnableManager.java
   cocoon/trunk/src/java/org/apache/cocoon/components/thread/DefaultThreadFactory.java
   cocoon/trunk/src/java/org/apache/cocoon/components/thread/RunnableManager.java
   cocoon/trunk/src/java/org/apache/cocoon/components/thread/ThreadFactory.java
   cocoon/trunk/src/webapp/WEB-INF/cocoon.xconf
Log:
after skimming the code Ithink we are in need of daemon mode too

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/thread/DefaultRunnableManager.java
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/thread/DefaultRunnableManager.java
(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/thread/DefaultRunnableManager.java
Sat Nov  6 05:54:31 2004
@@ -44,10 +44,11 @@
  *   <thread-pools>
  *     <thread-pool>  
  *       <name>default</name>
- *       <priority>NORM</priority> <!-- MIN | NORM | MAX
--> 
- *       <queue-size>-1</queue-size> <!-- <0 unbounded;
==0 no queue --> 
- *       <max-pool-size>-1</max-pool-size> <!-- ≤0
unbounded --> 
- *       <min-pool-size>2</min-pool-size> <!-- ≤0
not allowed -->
+ *       <priority>NORM</priority>
+ *       <daemon>false</daemon>
+ *       <queue-size>-1</queue-size>
+ *       <max-pool-size>-1</max-pool-size>
+ *       <min-pool-size>2</min-pool-size>
  *       <keep-alive-time-ms>20000</keep-alive-time-ms>
  *       <block-policy>RUN</block-policy>
  *       <shutdown-graceful>false</shutdown-graceful>
@@ -56,6 +57,13 @@
  *   </thread-pools>
  * </pre>
  * </p>
+ * 
+ * <p>
+ * Have a look at
+ * http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/PooledExecutor.html,
+ * {@link EDU.oswego.cs.dl.util.concurrent.PooledExecutor} or the cocoon.xconf
+ * file for more information.
+ * </p>
  *
  * @author <a href="mailto:giacomo.at.apache.org">Giacomo Pati</a>
  * @version $Id$
@@ -83,6 +91,9 @@
     /** The default thread priority */
     public static final String DEFAULT_THREAD_PRIORITY = "NORM";
 
+    /** The default daemon mode */
+    public static final boolean DEFAULT_DAEMON_MODE = false;
+
     /** The default keep alive time */
     public static final long DEFAULT_KEEP_ALIVE_TIME = 60000L;
 
@@ -152,6 +163,7 @@
                     msg.append( ",max-pool-size=" ).append( pool.getMaximumPoolSize(  ) );
                     msg.append( ",min-pool-size=" ).append( pool.getMinimumPoolSize(  ) );
                     msg.append( ",priority=" ).append( pool.getPriority(  ) );
+                    msg.append( ",isDaemon=" ).append( ( (ThreadFactory)pool.getThreadFactory(
 ) ).isDaemon(  ) );
                     msg.append( ",keep-alive-time-ms=" ).append( pool.getKeepAliveTime( 
) );
                     msg.append( ",block-policy=\"" ).append( pool.getBlockPolicy(  ) );
                     msg.append( "\",shutdown-wait-time-ms=" ).append( pool.getShutdownWaitTimeMs(
 ) );
@@ -165,6 +177,7 @@
                        .append( pool.getMaximumPoolSize(  ) );
                     msg.append( ",min-pool-size=" ).append( pool.getMinimumPoolSize(  ) );
                     msg.append( ",priority=" ).append( pool.getPriority(  ) );
+                    msg.append( ",isDaemon=" ).append( ( (ThreadFactory)pool.getThreadFactory(
 ) ).isDaemon(  ) );
                     msg.append( ",keep-alive-time-ms=" ).append( pool.getKeepAliveTime( 
) );
                     msg.append( ",block-policy=" ).append( pool.getBlockPolicy(  ) );
                     msg.append( ",shutdown-wait-time-ms=" ).append( pool.getShutdownWaitTimeMs(
 ) );
@@ -182,7 +195,7 @@
             createPool( DEFAULT_THREADPOOL_NAME, DEFAULT_QUEUE_SIZE,
                         DEFAULT_MAX_POOL_SIZE, DEFAULT_MIN_POOL_SIZE,
                         getPriority( DEFAULT_THREAD_PRIORITY ),
-                        DEFAULT_KEEP_ALIVE_TIME,
+                        DEFAULT_DAEMON_MODE, DEFAULT_KEEP_ALIVE_TIME,
                         DefaultThreadPool.POLICY_DEFAULT,
                         DEFAULT_SHUTDOWN_GRACEFUL, DEFAULT_SHUTDOWN_WAIT_TIME );
         }
@@ -198,6 +211,8 @@
      * @param priority The priority of threads created by this pool. This is
      *        one of {@link Thread#MIN_PRIORITY}, {@link
      *        Thread#NORM_PRIORITY}, or {@link Thread#MAX_PRIORITY}
+     * @param isDaemon Whether or not thread from the pool should run in daemon
+     *        mode
      * @param keepAliveTime How long should a thread be alive for new work to
      *        be done before it is GCed
      * @param blockPolicy What's the blocking policy is resources are exhausted
@@ -211,14 +226,15 @@
                             final int maxPoolSize,
                             final int minPoolSize,
                             final int priority,
+                            final boolean isDaemon,
                             final long keepAliveTime,
                             final String blockPolicy,
                             final boolean shutdownGraceful,
                             final int shutdownWaitTime )
     {
         createPool( new DefaultThreadPool(  ), name, queueSize, maxPoolSize,
-                    minPoolSize, priority, keepAliveTime, blockPolicy,
-                    shutdownGraceful, shutdownWaitTime );
+                    minPoolSize, priority, isDaemon, keepAliveTime,
+                    blockPolicy, shutdownGraceful, shutdownWaitTime );
     }
 
     /**
@@ -230,6 +246,8 @@
      * @param priority The priority of threads created by this pool. This is
      *        one of {@link Thread#MIN_PRIORITY}, {@link
      *        Thread#NORM_PRIORITY}, or {@link Thread#MAX_PRIORITY}
+     * @param isDaemon Whether or not thread from the pool should run in daemon
+     *        mode
      * @param keepAliveTime How long should a thread be alive for new work to
      *        be done before it is GCed
      * @param blockPolicy What's the blocking policy is resources are exhausted
@@ -244,6 +262,7 @@
                                   final int maxPoolSize,
                                   final int minPoolSize,
                                   final int priority,
+                                  final boolean isDaemon,
                                   final long keepAliveTime,
                                   final String blockPolicy,
                                   final boolean shutdownGraceful,
@@ -253,7 +272,7 @@
         final String name = "anon-" + pool.hashCode(  );
 
         return createPool( pool, name, queueSize, maxPoolSize, minPoolSize,
-                           priority, keepAliveTime, blockPolicy,
+                           priority, isDaemon, keepAliveTime, blockPolicy,
                            shutdownGraceful, shutdownWaitTime );
     }
 
@@ -562,6 +581,8 @@
 
         final String priority =
             config.getChild( "priority" ).getValue( DEFAULT_THREAD_PRIORITY );
+        final boolean isDaemon =
+            config.getChild( "daemon" ).getValueAsBoolean( DEFAULT_DAEMON_MODE );
         final long keepAliveTime =
             config.getChild( "keep-alive-time-ms" ).getValueAsLong( DEFAULT_KEEP_ALIVE_TIME
);
         final String blockPolicy =
@@ -573,8 +594,8 @@
 
         return createPool( new DefaultThreadPool(  ), name, queueSize,
                            maxPoolSize, minPoolSize, getPriority( priority ),
-                           keepAliveTime, blockPolicy, shutdownGraceful,
-                           shutdownWaitTime );
+                           isDaemon, keepAliveTime, blockPolicy,
+                           shutdownGraceful, shutdownWaitTime );
     }
 
     /**
@@ -588,6 +609,8 @@
      * @param priority The priority of threads created by this pool. This is
      *        one of {@link Thread#MIN_PRIORITY}, {@link
      *        Thread#NORM_PRIORITY}, or {@link Thread#MAX_PRIORITY}
+     * @param isDaemon Whether or not thread from the pool should run in daemon
+     *        mode
      * @param keepAliveTime How long should a thread be alive for new work to
      *        be done before it is GCed
      * @param blockPolicy What's the blocking policy is resources are exhausted
@@ -604,6 +627,7 @@
                                           final int maxPoolSize,
                                           final int minPoolSize,
                                           final int priority,
+                                          final boolean isDaemon,
                                           final long keepAliveTime,
                                           final String blockPolicy,
                                           final boolean shutdownGraceful,
@@ -629,6 +653,7 @@
         }
 
         factory.setPriority( priority );
+        factory.setDaemon( isDaemon );
         pool.setThreadFactory( factory );
         pool.setQueue( queueSize );
         pool.setMaximumPoolSize( maxPoolSize );

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/thread/DefaultThreadFactory.java
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/thread/DefaultThreadFactory.java	(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/thread/DefaultThreadFactory.java	Sat
Nov  6 05:54:31 2004
@@ -15,7 +15,6 @@
  */
 package org.apache.cocoon.components.thread;
 
-
 /**
  * This class is responsible to create new Thread instances to run a command.
  *
@@ -27,11 +26,40 @@
 {
     //~ Instance fields --------------------------------------------------------
 
+    /** The daemon mode */
+    private boolean m_isDaemon = false;
+
     /** The priority of newly created Threads */
     private int m_priority = Thread.NORM_PRIORITY;
 
+    //~ Methods ----------------------------------------------------------------
+
+    /**
+     * Set the isDaemon property
+     *
+     * @param isDaemon Whether or not new <code>Thread</code> should run as
+     *        daemons.
+     */
+    public void setDaemon( boolean isDaemon )
+    {
+        m_isDaemon = isDaemon;
+    }
+
     /**
-     * @see org.apache.cocoon.components.thread.ThreadFactory#setPriority(int)
+     * Get the isDaemon property
+     *
+     * @return Whether or not new <code>Thread</code> will run as daemons.
+     */
+    public boolean isDaemon(  )
+    {
+        return m_isDaemon;
+    }
+
+    /**
+     * Set the priority newly created <code>Thread</code>s should have
+     *
+     * @param priority One of {@link Thread#MIN_PRIORITY}, {@link
+     *        Thread#NORM_PRIORITY}, {@link Thread#MAX_PRIORITY}
      */
     public void setPriority( final int priority )
     {
@@ -43,15 +71,29 @@
         }
     }
 
-    //~ Methods ----------------------------------------------------------------
+    /**
+     * Get the priority newly created <code>Thread</code>s will have
+     *
+     * @return One of {@link Thread#MIN_PRIORITY}, {@link
+     *         Thread#NORM_PRIORITY}, {@link Thread#MAX_PRIORITY}
+     */
+    public int getPriority(  )
+    {
+        return m_priority;
+    }
 
     /**
-     * @see EDU.oswego.cs.dl.util.concurrent.ThreadFactory#newThread(java.lang.Runnable)
+     * Create a new Thread for Runnable
+     *
+     * @param command The {@link Runnable}
+     *
+     * @return A new Thread instance
      */
     public Thread newThread( final Runnable command )
     {
         final Thread thread = new Thread( command );
         thread.setPriority( m_priority );
+        thread.setDaemon( m_isDaemon );
 
         return thread;
     }

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/thread/RunnableManager.java
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/thread/RunnableManager.java	(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/thread/RunnableManager.java	Sat Nov
 6 05:54:31 2004
@@ -41,6 +41,8 @@
      * @param priority The priority of threads created by this pool. This is
      *        one of {@link Thread#MIN_PRIORITY}, {@link
      *        Thread#NORM_PRIORITY}, or {@link Thread#MAX_PRIORITY}
+     * @param isDaemon Whether or not thread from the pool should run in daemon
+     *        mode
      * @param keepAliveTime How long should a thread be alive for new work to
      *        be done before it is GCed
      * @param blockPolicy What's the blocking policy is resources are exhausted
@@ -54,6 +56,7 @@
                      int maxPoolSize,
                      int minPoolSize,
                      int priority,
+                     final boolean isDaemon,
                      long keepAliveTime,
                      String blockPolicy,
                      boolean shutdownGraceful,
@@ -68,6 +71,8 @@
      * @param priority The priority of threads created by this pool. This is
      *        one of {@link Thread#MIN_PRIORITY}, {@link
      *        Thread#NORM_PRIORITY}, or {@link Thread#MAX_PRIORITY}
+     * @param isDaemon Whether or not thread from the pool should run in daemon
+     *        mode
      * @param keepAliveTime How long should a thread be alive for new work to
      *        be done before it is GCed
      * @param blockPolicy What's the blocking policy is resources are exhausted
@@ -82,6 +87,7 @@
                            int maxPoolSize,
                            int minPoolSize,
                            int priority,
+                           final boolean isDaemon,
                            long keepAliveTime,
                            String blockPolicy,
                            boolean shutdownGraceful,

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/thread/ThreadFactory.java
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/thread/ThreadFactory.java	(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/thread/ThreadFactory.java	Sat Nov 
6 05:54:31 2004
@@ -22,17 +22,40 @@
  * @author <a href="mailto:giacomo.at.apache.org">Giacomo Pati</a>
  * @version CVS $Id$
  */
-public interface ThreadFactory extends EDU.oswego.cs.dl.util.concurrent.ThreadFactory
+public interface ThreadFactory
+    extends EDU.oswego.cs.dl.util.concurrent.ThreadFactory
 {
     //~ Methods ----------------------------------------------------------------
 
     /**
+     * Set the daemon mode of created <code>Thread</code>s should have
+     *
+     * @param isDaemon Whether new {@link Thread}s should run as daemons.
+     */
+    void setDaemon( boolean isDaemon );
+
+    /**
+     * Get the daemon mode created <code>Thread</code>s will have
+     *
+     * @return Whether new {@link Thread}s should run as daemons.
+     */
+    boolean isDaemon(  );
+
+    /**
      * Set the priority newly created <code>Thread</code>s should have
      *
      * @param priority One of {@link Thread#MIN_PRIORITY}, {@link
      *        Thread#NORM_PRIORITY}, {@link Thread#MAX_PRIORITY}
      */
     void setPriority( int priority );
+
+    /**
+     * Get the priority newly created <code>Thread</code>s will have
+     *
+     * @return One of {@link Thread#MIN_PRIORITY}, {@link
+     *         Thread#NORM_PRIORITY}, {@link Thread#MAX_PRIORITY}
+     */
+    int getPriority(  );
 
     /**
      * Create a new Thread for a {@link Runnable} command

Modified: cocoon/trunk/src/webapp/WEB-INF/cocoon.xconf
==============================================================================
--- cocoon/trunk/src/webapp/WEB-INF/cocoon.xconf	(original)
+++ cocoon/trunk/src/webapp/WEB-INF/cocoon.xconf	Sat Nov  6 05:54:31 2004
@@ -575,6 +575,8 @@
         |                          MIN:  corresponds to Thread#MIN_PRIORITY
         |                          NORM: corresponds to Thread#NORM_PRIORITY (default)
         |                          MAX:  corresponds to Thread#MAX_PRIORITY
+        | daemon:                whether newly created Threads should run in 
+        |                        daemon mode or not. Default to false.
         | queue-size:            optional size of a queue to hold Runnables if the 
         |                        pool is full. Possible values are:
         |                          less than 0:    unbounded (default)
@@ -626,6 +628,7 @@
       <thread-pool>  
         <name>default</name>
         <priority>NORM</priority>
+        <daemon>false</daemon>
         <queue-size>-1</queue-size>
         <max-pool-size>5</max-pool-size>
         <min-pool-size>5</min-pool-size>

Mime
View raw message