geirm       00/11/12 09:59:25

  Modified:    src/java/org/apache/velocity/servlet VelocityServlet.java
  Log:
  Replaced the writer Stack() with a SimplePool() for protection of the writers, and 
fixed a small bug where the writer was flushed after(!) it was returned to the pool.
  
  Revision  Changes    Path
  1.16      +12 -13    
jakarta-velocity/src/java/org/apache/velocity/servlet/VelocityServlet.java
  
  Index: VelocityServlet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/servlet/VelocityServlet.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- VelocityServlet.java      2000/11/07 23:13:52     1.15
  +++ VelocityServlet.java      2000/11/12 17:59:25     1.16
  @@ -77,6 +77,8 @@
   
   import org.apache.velocity.io.*;
   
  +import org.apache.velocity.util.*;
  +
   /**
    * Base class which simplifies the use of Velocity with Servlets.
    * Extend this class, implement the <code>handleRequest()</code> method, 
  @@ -98,7 +100,8 @@
    *
    * @author Dave Bryson
    * @author <a href="mailto:[EMAIL PROTECTED]">Jon S. Stevens</a>
  - * $Id: VelocityServlet.java,v 1.15 2000/11/07 23:13:52 jon Exp $
  + * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
  + * $Id: VelocityServlet.java,v 1.16 2000/11/12 17:59:25 geirm Exp $
    */
   public abstract class VelocityServlet extends HttpServlet
   {
  @@ -136,8 +139,9 @@
       /**
        * Cache of writers
        */
  -    private static Stack writerStack = new Stack();
  -    
  +   
  +    private static SimplePool writerPool = new SimplePool(40);
  +   
       /** 
        * Performs initialization of this servlet.  Called by the servlet 
        * container on loading.
  @@ -241,20 +245,15 @@
               if ( template == null )
                   throw new Exception ("Cannot find the template!" );
               
  -            try
  -            {
  -                vw = (JspWriterImpl) writerStack.pop();
  -            }
  -            catch (Exception e)
  -            {
  -            }
  +          
  +            vw = (JspWriterImpl) writerPool.get();
  +          
               if (vw == null)
                   vw = new JspWriterImpl(new OutputStreamWriter(output, encoding), 
4*1024, true);
               else
                   vw.recycle(new OutputStreamWriter(output, encoding));
  +           
               template.merge( context, vw);
  -
  -            //Writer vw = new BufferedWriter(new OutputStreamWriter(output));
           }
           catch (Exception e)
           {
  @@ -267,8 +266,8 @@
               {
                   if (vw != null)
                   {
  -                    writerStack.push(vw);
                       vw.flush();
  +                    writerPool.put(vw);
                       output.close();
                   }                
               }
  
  
  

Reply via email to