You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by la...@marchex.com on 2005/05/05 22:53:44 UTC

OutOfMemoryException Processing Velocity Template

I am getting an OutOfMemoryException:

org.apache.velocity.exception.MethodInvocationException: Invocation of method 'get' in  class org.apache.velocity.tools.struts.TilesTool threw exception class java.lang.OutOfMemoryError : null

when I am creating a large velocity file.  The vm file itself is fairly small, but this piece of velocity is causing the exception:

#foreach($row in $List)
<tr>
<td height="20" class="tbltxt">$!row.item1</td>
<td class="tbltxt">$!row.item2</td>
<td class="tbltxt">$!row.item3</td>
<td class="tbltxt">$!row.item4</td>
<td class="tbltxt">$!number.format('currency', $!row.item5)</td>
</tr>
#end

List is a list of relatively small objects (5-6 Strings, a couple of BigDecimals), but the List itself contains approximately 66,000 entries.  Unfortunately, unless I set the tomcat JVM to use a heap size of at least 256M, this velocity template throws an OutOfMemoryException when it is being processed.   

Any suggestions?

Thanks.

-L

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Problems with Overloaded Methods

Posted by Tim Diggins <su...@red56.co.uk>.
Hi -

I will try to recreate (cause I've worked around it now and I never 
committed (not surprisingly) the broken version to my code-repos) the 
problem and submit a code fragment here (though I've looked at the code 
in the MethodMap and don't get why it wouldn't work (I've even put the 
formal.isAssignableFrom(actual) into the relevant place in my template 
and get the right answer)).

However, from a theoretical point of view, I can see why there is some 
confusion around this -- or at least, I saw why __I__ was confused: I 
did some useful reading (e.g. Effective Java, Joshua Bloch (Addison 
Wesley) -  Item 26 "Use overloading judiciously) and finally understood 
that the choice of which overloaded method to choose is meant to occur 
at COMPILE time (not run time, unlike method overriding which does occur 
at Run time)... and of course the velocity template never really exists 
at Compile time, it is a run-time construct (hence use of 
introspection)... In fact Bloch recommends  minimising the use of 
overloads for this reason - it is not a way of discriminating runtime 
type. Thus (perversely), overloading code within "regular" 
(non-introspected) java often uses the (often frowned on) instanceof to 
discriminate type... e.g.

public static String Classify(Collection c) {
   return (c instanceof Set ? "Set" : (c instanceof List ? "List" : 
"UnknownCollection"));
} //from Bloch, p 130

Not sure where this leaves overloaded methods in an 
introspection-powered framework like velocity.

-- Tim


Shinobu Kawai wrote:
> Hi Tim,
> 
> 
>>>I noticed that Attila Szegedi (from 2002 - see
>>>http://mail-archives.apache.org/mod_mbox/jakarta-velocity-dev/200203.mbox/%3CB8BE204E.17A0A%25geirm@optonline.net%3E).
>>>was offering to change the (then) current velocity mechanism for
>>>introspecting the correct overload so it matched the JLS mechanism...
>>>Did this ever happen?
>>
>>Looks like it was reflected on SVN revision 75625.  So yours might be
>>another problem.
> 
> 
> I just tried a few, but it works for me.  Could you give an example of
> the failing code?
> 
> Best regards,
> -- Shinobu
> 
> --
> Shinobu Kawai <sh...@gmail.com>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Problems with Overloaded Methods

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Tim,

> > I noticed that Attila Szegedi (from 2002 - see
> > http://mail-archives.apache.org/mod_mbox/jakarta-velocity-dev/200203.mbox/%3CB8BE204E.17A0A%25geirm@optonline.net%3E).
> > was offering to change the (then) current velocity mechanism for
> > introspecting the correct overload so it matched the JLS mechanism...
> > Did this ever happen?
> 
> Looks like it was reflected on SVN revision 75625.  So yours might be
> another problem.

I just tried a few, but it works for me.  Could you give an example of
the failing code?

Best regards,
-- Shinobu

--
Shinobu Kawai <sh...@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Problems with Overloaded Methods

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Tim,

> I noticed that Attila Szegedi (from 2002 - see
> http://mail-archives.apache.org/mod_mbox/jakarta-velocity-dev/200203.mbox/%3CB8BE204E.17A0A%25geirm@optonline.net%3E).
> was offering to change the (then) current velocity mechanism for
> introspecting the correct overload so it matched the JLS mechanism...
> Did this ever happen?

Looks like it was reflected on SVN revision 75625.  So yours might be
another problem.
    http://svn.apache.org/viewcvs.cgi/jakarta/velocity/trunk/src/java/org/apache/velocity/util/introspection/MethodMap.java?rev=75625&view=log

Best regards,
-- Shinobu

--
Shinobu Kawai <sh...@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Problems with Overloaded Methods

Posted by Will Glass-Husain <wg...@forio.com>.
Hi Tim,

I'm not familiar with this specific issue, but it sounds like a possible 
bug.  To answer your question, I don't think there's a good writeup.

Would you mind posting this in Bugzilla?
http://issues.apache.org/bugzilla/

Thanks!

WILL

----- Original Message ----- 
From: "Tim Diggins" <su...@red56.co.uk>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Friday, May 06, 2005 4:13 AM
Subject: Problems with Overloaded Methods


> Hi -
>
> I'm having problems when calling overloaded methods from a vm template. 
> Typically this is a $util.makeHref($thing), where makeHref has several 
> overloads. If there is in an exact match between the method class and the 
> runtime classe of $thing, then there isn't a problem. But if $thing is a 
> subtype of one of the overloads (implementation or extension) then 
> velocity seems not to find it (just prints $util.makeHref($thing). (And 
> once (I can't repeat it) I got a null pointer error within the velocity 
> classes (no reference to my code at all in the traceback) - this may have 
> been my error, but I __think__ it was actually some kind of introspection 
> problem with a complicated set of overloaded methods).
>
> I noticed that Attila Szegedi (from 2002 - see 
> http://mail-archives.apache.org/mod_mbox/jakarta-velocity-dev/200203.mbox/%3CB8BE204E.17A0A%25geirm@optonline.net%3E).
> was offering to change the (then) current velocity mechanism for 
> introspecting the correct overload so it matched the JLS mechanism... Did 
> this ever happen?
>
> More importantly (I think) is there any write-up of the current mechanism 
> (heuristic) that velocity uses?
>
> (Apologies if I ought to have put this on the dev list, but I feel it is 
> really a user question, so ought to check the user list first.)
>
> many thanks
>
> Tim Diggins
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Problems with Overloaded Methods

Posted by Llewellyn Falco <is...@setgame.com>.
I had a simular problem with
asJavascript(String s)
asJavascript(Number n)

and my work arround was to overload a thrid time as

asJavascript(Object o)
{
  if (o ==  null)                        {return "null";}
  else if (o instanceof Number){return asJavascript((Number)o);}
  else                                      { return 
asJavascript(o.toString);}
}


it's a bit o cludge, but ....



llewellyn. 


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Problems with Overloaded Methods

Posted by Tim Diggins <su...@red56.co.uk>.
Hi -

I'm having problems when calling overloaded methods from a vm template. 
Typically this is a $util.makeHref($thing), where makeHref has several 
overloads. If there is in an exact match between the method class and 
the runtime classe of $thing, then there isn't a problem. But if $thing 
is a subtype of one of the overloads (implementation or extension) then 
velocity seems not to find it (just prints $util.makeHref($thing). (And 
once (I can't repeat it) I got a null pointer error within the velocity 
classes (no reference to my code at all in the traceback) - this may 
have been my error, but I __think__ it was actually some kind of 
introspection problem with a complicated set of overloaded methods).

I noticed that Attila Szegedi (from 2002 - see 
http://mail-archives.apache.org/mod_mbox/jakarta-velocity-dev/200203.mbox/%3CB8BE204E.17A0A%25geirm@optonline.net%3E).
was offering to change the (then) current velocity mechanism for 
introspecting the correct overload so it matched the JLS mechanism... 
Did this ever happen?

More importantly (I think) is there any write-up of the current 
mechanism (heuristic) that velocity uses?

(Apologies if I ought to have put this on the dev list, but I feel it is 
really a user question, so ought to check the user list first.)

many thanks

Tim Diggins


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: OutOfMemoryException Processing Velocity Template

Posted by la...@marchex.com.
Alright, I ran this little piece of code:

public static void main( String args[] ) throws Exception
    {
        /* first, we init the runtime engine.  Defaults are fine. */

        Velocity.init();

        /* lets make a Context and put data into it */

        VelocityContext context = new VelocityContext();

        List results = ReportBean.runLargeReport();
        
        context.put("List", results);
        
        /* lets render a template */

        StringWriter w = new StringWriter();

        Velocity.mergeTemplate("/myfile.vm", context, w );
        System.out.println(" template : " + w );

        /* lets make our own string to render */
    }

results is a List of 66000 objects and requires about 8megs of memory.   The "mergeTemplate" requires at least 230 MB of memory.   Any suggestions?

-L

On Fri, May 06, 2005 at 11:53:30AM -0700, jian chen wrote:
> Hi, 
> 
> I guess the writer Ilkka talked about is when using Velocity as a
> standalone template engine.
> 
> Right now I don't have a good clue, could you run Velocity as a
> standalone template engine and render the page to see if there is a
> huge memory usage?
> 
> Cheers,
> 
> Jian
> 
> On 5/6/05, lawrence@marchex.com <la...@marchex.com> wrote:
> > Sorry, I'm not sure what you mean by what "kind of writer" I'm using.   Where would I find out?   How would I change this (to maybe a StringBuffer writer?)
> > 
> > Also, each column contains a String that is at most, 200 characters, most are closer to 10-20.   There are a total of 10 columns.
> > 
> > Thanks.
> > 
> > -Lawrence
> > 
> > On Fri, May 06, 2005 at 09:11:13PM +0300, Ilkka Priha wrote:
> > > What kind of writer are you using and how long are the items? 66 000 HTML
> > > table rows with 5 numeric columns consumes about 32 MB when buffered into a
> > > string writer. If the items are longer, it takes much more memory.
> > >
> > > -- Ilkka
> > >
> > >
> > > lawrence@marchex.com wrote:
> > > >I tried putting static HTML in the #foreach loop, same problem.  Then I
> > > >tried setting the large list as a "local" varible:
> > > >
> > > >#set ($localList = $List)
> > > >#foreach($row in $localList)
> > > >...
> > > >
> > > >but that didnt help either.   I don't see why velocity should use 250+ MB
> > > >of memory iterating over a list ~8MB in size...
> > > >-L
> > > >
> > > >On Thu, May 05, 2005 at 02:56:28PM -0700, jian chen wrote:
> > > >
> > > >>Well, I don't have a good clue now.
> > > >>
> > > >>What about do the debugging step by step, i.e., use just static html
> > > >>in your #foreach loop? Will that blow up the memory?
> > > >>
> > > >>Cheers,
> > > >>
> > > >>Jian
> > > >>
> > > >>
> > > >>
> > > >>On 5/5/05, lawrence@marchex.com <la...@marchex.com> wrote:
> > > >>
> > > >>>Thanks for the suggestion.   I tried putting that, along with
> > > >>>
> > > >>>file.resource.loader.cache = true
> > > >>>
> > > >>>in my velocity.properties file.   Both did not work.   Any other
> > > >>>suggestions?
> > > >>>
> > > >>>Thanks!
> > > >>>
> > > >>>-L
> > > >>>
> > > >>>On Thu, May 05, 2005 at 02:11:28PM -0700, jian chen wrote:
> > > >>>
> > > >>>>Hi,
> > > >>>>
> > > >>>>This maybe because you haven't turned on template caching. I had
> > > >>>>similar problem before, and even if I only used evaluate(...) method
> > > >>>>and load the template using my own java program, it happened when the
> > > >>>>for loop is lot of iterations.
> > > >>>>
> > > >>>>The bottom line for my problem is I need to turn on template caching,
> > > >>>>so, velocity will not try to cache the objects it parsed during each
> > > >>>>time of the iteration.
> > > >>>>
> > > >>>>I did:
> > > >>>>ri.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, "true");
> > > >>>>
> > > >>>>where ri is a runtime instance.
> > > >>>>
> > > >>>>Will this fix your issue?
> > > >>>>
> > > >>>>Cheers,
> > > >>>>
> > > >>>>Jian
> > > >>>>
> > > >>>>
> > > >>>>On 5/5/05, lawrence@marchex.com <la...@marchex.com> wrote:
> > > >>>>
> > > >>>>>I am getting an OutOfMemoryException:
> > > >>>>>
> > > >>>>>org.apache.velocity.exception.MethodInvocationException: Invocation of
> > > >>>>>method 'get' in  class org.apache.velocity.tools.struts.TilesTool
> > > >>>>>threw exception class java.lang.OutOfMemoryError : null
> > > >>>>>
> > > >>>>>when I am creating a large velocity file.  The vm file itself is
> > > >>>>>fairly small, but this piece of velocity is causing the exception:
> > > >>>>>
> > > >>>>>#foreach($row in $List)
> > > >>>>><tr>
> > > >>>>><td height="20" class="tbltxt">$!row.item1</td>
> > > >>>>><td class="tbltxt">$!row.item2</td>
> > > >>>>><td class="tbltxt">$!row.item3</td>
> > > >>>>><td class="tbltxt">$!row.item4</td>
> > > >>>>><td class="tbltxt">$!number.format('currency', $!row.item5)</td>
> > > >>>>></tr>
> > > >>>>>#end
> > > >>>>>
> > > >>>>>List is a list of relatively small objects (5-6 Strings, a couple of
> > > >>>>>BigDecimals), but the List itself contains approximately 66,000
> > > >>>>>entries.  Unfortunately, unless I set the tomcat JVM to use a heap
> > > >>>>>size of at least 256M, this velocity template throws an
> > > >>>>>OutOfMemoryException when it is being processed.
> > > >>>>>
> > > >>>>>Any suggestions?
> > > >>>>>
> > > >>>>>Thanks.
> > > >>>>>
> > > >>>>>-L
> > > >>>>>
> > > >>>>>---------------------------------------------------------------------
> > > >>>>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > > >>>>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> > > >>>>>
> > > >>>>>
> > > >>>>
> > > >>>>---------------------------------------------------------------------
> > > >>>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > > >>>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> > > >>>
> > > >>>---------------------------------------------------------------------
> > > >>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > > >>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> > > >>>
> > > >>>
> > > >>
> > > >>---------------------------------------------------------------------
> > > >>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > > >>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> > > >
> > > >
> > > >---------------------------------------------------------------------
> > > >To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > > >For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> > > >
> > > >.
> > > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> > 
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: OutOfMemoryException Processing Velocity Template

Posted by jian chen <ch...@gmail.com>.
Hi, 

I guess the writer Ilkka talked about is when using Velocity as a
standalone template engine.

Right now I don't have a good clue, could you run Velocity as a
standalone template engine and render the page to see if there is a
huge memory usage?

Cheers,

Jian

On 5/6/05, lawrence@marchex.com <la...@marchex.com> wrote:
> Sorry, I'm not sure what you mean by what "kind of writer" I'm using.   Where would I find out?   How would I change this (to maybe a StringBuffer writer?)
> 
> Also, each column contains a String that is at most, 200 characters, most are closer to 10-20.   There are a total of 10 columns.
> 
> Thanks.
> 
> -Lawrence
> 
> On Fri, May 06, 2005 at 09:11:13PM +0300, Ilkka Priha wrote:
> > What kind of writer are you using and how long are the items? 66 000 HTML
> > table rows with 5 numeric columns consumes about 32 MB when buffered into a
> > string writer. If the items are longer, it takes much more memory.
> >
> > -- Ilkka
> >
> >
> > lawrence@marchex.com wrote:
> > >I tried putting static HTML in the #foreach loop, same problem.  Then I
> > >tried setting the large list as a "local" varible:
> > >
> > >#set ($localList = $List)
> > >#foreach($row in $localList)
> > >...
> > >
> > >but that didnt help either.   I don't see why velocity should use 250+ MB
> > >of memory iterating over a list ~8MB in size...
> > >-L
> > >
> > >On Thu, May 05, 2005 at 02:56:28PM -0700, jian chen wrote:
> > >
> > >>Well, I don't have a good clue now.
> > >>
> > >>What about do the debugging step by step, i.e., use just static html
> > >>in your #foreach loop? Will that blow up the memory?
> > >>
> > >>Cheers,
> > >>
> > >>Jian
> > >>
> > >>
> > >>
> > >>On 5/5/05, lawrence@marchex.com <la...@marchex.com> wrote:
> > >>
> > >>>Thanks for the suggestion.   I tried putting that, along with
> > >>>
> > >>>file.resource.loader.cache = true
> > >>>
> > >>>in my velocity.properties file.   Both did not work.   Any other
> > >>>suggestions?
> > >>>
> > >>>Thanks!
> > >>>
> > >>>-L
> > >>>
> > >>>On Thu, May 05, 2005 at 02:11:28PM -0700, jian chen wrote:
> > >>>
> > >>>>Hi,
> > >>>>
> > >>>>This maybe because you haven't turned on template caching. I had
> > >>>>similar problem before, and even if I only used evaluate(...) method
> > >>>>and load the template using my own java program, it happened when the
> > >>>>for loop is lot of iterations.
> > >>>>
> > >>>>The bottom line for my problem is I need to turn on template caching,
> > >>>>so, velocity will not try to cache the objects it parsed during each
> > >>>>time of the iteration.
> > >>>>
> > >>>>I did:
> > >>>>ri.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, "true");
> > >>>>
> > >>>>where ri is a runtime instance.
> > >>>>
> > >>>>Will this fix your issue?
> > >>>>
> > >>>>Cheers,
> > >>>>
> > >>>>Jian
> > >>>>
> > >>>>
> > >>>>On 5/5/05, lawrence@marchex.com <la...@marchex.com> wrote:
> > >>>>
> > >>>>>I am getting an OutOfMemoryException:
> > >>>>>
> > >>>>>org.apache.velocity.exception.MethodInvocationException: Invocation of
> > >>>>>method 'get' in  class org.apache.velocity.tools.struts.TilesTool
> > >>>>>threw exception class java.lang.OutOfMemoryError : null
> > >>>>>
> > >>>>>when I am creating a large velocity file.  The vm file itself is
> > >>>>>fairly small, but this piece of velocity is causing the exception:
> > >>>>>
> > >>>>>#foreach($row in $List)
> > >>>>><tr>
> > >>>>><td height="20" class="tbltxt">$!row.item1</td>
> > >>>>><td class="tbltxt">$!row.item2</td>
> > >>>>><td class="tbltxt">$!row.item3</td>
> > >>>>><td class="tbltxt">$!row.item4</td>
> > >>>>><td class="tbltxt">$!number.format('currency', $!row.item5)</td>
> > >>>>></tr>
> > >>>>>#end
> > >>>>>
> > >>>>>List is a list of relatively small objects (5-6 Strings, a couple of
> > >>>>>BigDecimals), but the List itself contains approximately 66,000
> > >>>>>entries.  Unfortunately, unless I set the tomcat JVM to use a heap
> > >>>>>size of at least 256M, this velocity template throws an
> > >>>>>OutOfMemoryException when it is being processed.
> > >>>>>
> > >>>>>Any suggestions?
> > >>>>>
> > >>>>>Thanks.
> > >>>>>
> > >>>>>-L
> > >>>>>
> > >>>>>---------------------------------------------------------------------
> > >>>>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > >>>>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> > >>>>>
> > >>>>>
> > >>>>
> > >>>>---------------------------------------------------------------------
> > >>>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > >>>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> > >>>
> > >>>---------------------------------------------------------------------
> > >>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > >>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> > >>>
> > >>>
> > >>
> > >>---------------------------------------------------------------------
> > >>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > >>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> > >
> > >
> > >---------------------------------------------------------------------
> > >To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > >For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> > >
> > >.
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: OutOfMemoryException Processing Velocity Template

Posted by la...@marchex.com.
Sorry, I'm not sure what you mean by what "kind of writer" I'm using.   Where would I find out?   How would I change this (to maybe a StringBuffer writer?)

Also, each column contains a String that is at most, 200 characters, most are closer to 10-20.   There are a total of 10 columns.

Thanks.

-Lawrence

On Fri, May 06, 2005 at 09:11:13PM +0300, Ilkka Priha wrote:
> What kind of writer are you using and how long are the items? 66 000 HTML 
> table rows with 5 numeric columns consumes about 32 MB when buffered into a 
> string writer. If the items are longer, it takes much more memory.
> 
> -- Ilkka
> 
> 
> lawrence@marchex.com wrote:
> >I tried putting static HTML in the #foreach loop, same problem.  Then I 
> >tried setting the large list as a "local" varible:
> >
> >#set ($localList = $List)
> >#foreach($row in $localList)
> >...
> >
> >but that didnt help either.   I don't see why velocity should use 250+ MB 
> >of memory iterating over a list ~8MB in size...  
> >-L
> >
> >On Thu, May 05, 2005 at 02:56:28PM -0700, jian chen wrote:
> >
> >>Well, I don't have a good clue now. 
> >>
> >>What about do the debugging step by step, i.e., use just static html
> >>in your #foreach loop? Will that blow up the memory?
> >>
> >>Cheers,
> >>
> >>Jian
> >>
> >>
> >>
> >>On 5/5/05, lawrence@marchex.com <la...@marchex.com> wrote:
> >>
> >>>Thanks for the suggestion.   I tried putting that, along with
> >>>
> >>>file.resource.loader.cache = true
> >>>
> >>>in my velocity.properties file.   Both did not work.   Any other 
> >>>suggestions?
> >>>
> >>>Thanks!
> >>>
> >>>-L
> >>>
> >>>On Thu, May 05, 2005 at 02:11:28PM -0700, jian chen wrote:
> >>>
> >>>>Hi,
> >>>>
> >>>>This maybe because you haven't turned on template caching. I had
> >>>>similar problem before, and even if I only used evaluate(...) method
> >>>>and load the template using my own java program, it happened when the
> >>>>for loop is lot of iterations.
> >>>>
> >>>>The bottom line for my problem is I need to turn on template caching,
> >>>>so, velocity will not try to cache the objects it parsed during each
> >>>>time of the iteration.
> >>>>
> >>>>I did:
> >>>>ri.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, "true");
> >>>>
> >>>>where ri is a runtime instance.
> >>>>
> >>>>Will this fix your issue?
> >>>>
> >>>>Cheers,
> >>>>
> >>>>Jian
> >>>>
> >>>>
> >>>>On 5/5/05, lawrence@marchex.com <la...@marchex.com> wrote:
> >>>>
> >>>>>I am getting an OutOfMemoryException:
> >>>>>
> >>>>>org.apache.velocity.exception.MethodInvocationException: Invocation of 
> >>>>>method 'get' in  class org.apache.velocity.tools.struts.TilesTool 
> >>>>>threw exception class java.lang.OutOfMemoryError : null
> >>>>>
> >>>>>when I am creating a large velocity file.  The vm file itself is 
> >>>>>fairly small, but this piece of velocity is causing the exception:
> >>>>>
> >>>>>#foreach($row in $List)
> >>>>><tr>
> >>>>><td height="20" class="tbltxt">$!row.item1</td>
> >>>>><td class="tbltxt">$!row.item2</td>
> >>>>><td class="tbltxt">$!row.item3</td>
> >>>>><td class="tbltxt">$!row.item4</td>
> >>>>><td class="tbltxt">$!number.format('currency', $!row.item5)</td>
> >>>>></tr>
> >>>>>#end
> >>>>>
> >>>>>List is a list of relatively small objects (5-6 Strings, a couple of 
> >>>>>BigDecimals), but the List itself contains approximately 66,000 
> >>>>>entries.  Unfortunately, unless I set the tomcat JVM to use a heap 
> >>>>>size of at least 256M, this velocity template throws an 
> >>>>>OutOfMemoryException when it is being processed.
> >>>>>
> >>>>>Any suggestions?
> >>>>>
> >>>>>Thanks.
> >>>>>
> >>>>>-L
> >>>>>
> >>>>>---------------------------------------------------------------------
> >>>>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> >>>>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >>>>>
> >>>>>
> >>>>
> >>>>---------------------------------------------------------------------
> >>>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> >>>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >>>
> >>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> >>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >>>
> >>>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> >.
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: OutOfMemoryException Processing Velocity Template

Posted by Ilkka Priha <im...@surfeu.fi>.
What kind of writer are you using and how long are the items? 66 000 HTML table 
rows with 5 numeric columns consumes about 32 MB when buffered into a string 
writer. If the items are longer, it takes much more memory.

-- Ilkka


lawrence@marchex.com wrote:
> I tried putting static HTML in the #foreach loop, same problem.  Then I tried setting the large list as a "local" varible:
> 
> #set ($localList = $List)
> #foreach($row in $localList)
> ...
> 
> but that didnt help either.   I don't see why velocity should use 250+ MB of memory iterating over a list ~8MB in size...  
> 
> -L
> 
> On Thu, May 05, 2005 at 02:56:28PM -0700, jian chen wrote:
> 
>>Well, I don't have a good clue now. 
>>
>>What about do the debugging step by step, i.e., use just static html
>>in your #foreach loop? Will that blow up the memory?
>>
>>Cheers,
>>
>>Jian
>>
>>
>>
>>On 5/5/05, lawrence@marchex.com <la...@marchex.com> wrote:
>>
>>>Thanks for the suggestion.   I tried putting that, along with
>>>
>>>file.resource.loader.cache = true
>>>
>>>in my velocity.properties file.   Both did not work.   Any other suggestions?
>>>
>>>Thanks!
>>>
>>>-L
>>>
>>>On Thu, May 05, 2005 at 02:11:28PM -0700, jian chen wrote:
>>>
>>>>Hi,
>>>>
>>>>This maybe because you haven't turned on template caching. I had
>>>>similar problem before, and even if I only used evaluate(...) method
>>>>and load the template using my own java program, it happened when the
>>>>for loop is lot of iterations.
>>>>
>>>>The bottom line for my problem is I need to turn on template caching,
>>>>so, velocity will not try to cache the objects it parsed during each
>>>>time of the iteration.
>>>>
>>>>I did:
>>>>ri.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, "true");
>>>>
>>>>where ri is a runtime instance.
>>>>
>>>>Will this fix your issue?
>>>>
>>>>Cheers,
>>>>
>>>>Jian
>>>>
>>>>
>>>>On 5/5/05, lawrence@marchex.com <la...@marchex.com> wrote:
>>>>
>>>>>I am getting an OutOfMemoryException:
>>>>>
>>>>>org.apache.velocity.exception.MethodInvocationException: Invocation of method 'get' in  class org.apache.velocity.tools.struts.TilesTool threw exception class java.lang.OutOfMemoryError : null
>>>>>
>>>>>when I am creating a large velocity file.  The vm file itself is fairly small, but this piece of velocity is causing the exception:
>>>>>
>>>>>#foreach($row in $List)
>>>>><tr>
>>>>><td height="20" class="tbltxt">$!row.item1</td>
>>>>><td class="tbltxt">$!row.item2</td>
>>>>><td class="tbltxt">$!row.item3</td>
>>>>><td class="tbltxt">$!row.item4</td>
>>>>><td class="tbltxt">$!number.format('currency', $!row.item5)</td>
>>>>></tr>
>>>>>#end
>>>>>
>>>>>List is a list of relatively small objects (5-6 Strings, a couple of BigDecimals), but the List itself contains approximately 66,000 entries.  Unfortunately, unless I set the tomcat JVM to use a heap size of at least 256M, this velocity template throws an OutOfMemoryException when it is being processed.
>>>>>
>>>>>Any suggestions?
>>>>>
>>>>>Thanks.
>>>>>
>>>>>-L
>>>>>
>>>>>---------------------------------------------------------------------
>>>>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>>>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>>>>
>>>>>
>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>>
>>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
> .
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: OutOfMemoryException Processing Velocity Template

Posted by la...@marchex.com.
Ok, I think I've located the problem, although I can't think of a reasonable solution.   

Basically, if I make the #foreach loop EMPTY, it uses barely any memory:
#foreach($row in $List)

#end

As I add more to the body of the #foreach:
#foreach($row in $List)
<tr>
</tr>
#end

The amount of memory starts to grow (exponentially?).  

I did some playing around, and found that this:

#foreach($row in $List)
<tr>
<td height="20" class="tbltxt">$!row.item1</td>
<td class="tbltxt">$!row.item2</td>
<td class="tbltxt">$!row.item3</td>
</tr>
#end

Uses approximately 100+ MB of memory.   Something is going on ... but I have no clue what it is.

-L


On Fri, May 06, 2005 at 10:36:25AM -0700, lawrence@marchex.com wrote:
> I tried putting static HTML in the #foreach loop, same problem.  Then I tried setting the large list as a "local" varible:
> 
> #set ($localList = $List)
> #foreach($row in $localList)
> ...
> 
> but that didnt help either.   I don't see why velocity should use 250+ MB of memory iterating over a list ~8MB in size...  
> 
> -L
> 
> On Thu, May 05, 2005 at 02:56:28PM -0700, jian chen wrote:
> > Well, I don't have a good clue now. 
> > 
> > What about do the debugging step by step, i.e., use just static html
> > in your #foreach loop? Will that blow up the memory?
> > 
> > Cheers,
> > 
> > Jian
> > 
> > 
> > 
> > On 5/5/05, lawrence@marchex.com <la...@marchex.com> wrote:
> > > Thanks for the suggestion.   I tried putting that, along with
> > > 
> > > file.resource.loader.cache = true
> > > 
> > > in my velocity.properties file.   Both did not work.   Any other suggestions?
> > > 
> > > Thanks!
> > > 
> > > -L
> > > 
> > > On Thu, May 05, 2005 at 02:11:28PM -0700, jian chen wrote:
> > > > Hi,
> > > >
> > > > This maybe because you haven't turned on template caching. I had
> > > > similar problem before, and even if I only used evaluate(...) method
> > > > and load the template using my own java program, it happened when the
> > > > for loop is lot of iterations.
> > > >
> > > > The bottom line for my problem is I need to turn on template caching,
> > > > so, velocity will not try to cache the objects it parsed during each
> > > > time of the iteration.
> > > >
> > > > I did:
> > > > ri.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, "true");
> > > >
> > > > where ri is a runtime instance.
> > > >
> > > > Will this fix your issue?
> > > >
> > > > Cheers,
> > > >
> > > > Jian
> > > >
> > > >
> > > > On 5/5/05, lawrence@marchex.com <la...@marchex.com> wrote:
> > > > > I am getting an OutOfMemoryException:
> > > > >
> > > > > org.apache.velocity.exception.MethodInvocationException: Invocation of method 'get' in  class org.apache.velocity.tools.struts.TilesTool threw exception class java.lang.OutOfMemoryError : null
> > > > >
> > > > > when I am creating a large velocity file.  The vm file itself is fairly small, but this piece of velocity is causing the exception:
> > > > >
> > > > > #foreach($row in $List)
> > > > > <tr>
> > > > > <td height="20" class="tbltxt">$!row.item1</td>
> > > > > <td class="tbltxt">$!row.item2</td>
> > > > > <td class="tbltxt">$!row.item3</td>
> > > > > <td class="tbltxt">$!row.item4</td>
> > > > > <td class="tbltxt">$!number.format('currency', $!row.item5)</td>
> > > > > </tr>
> > > > > #end
> > > > >
> > > > > List is a list of relatively small objects (5-6 Strings, a couple of BigDecimals), but the List itself contains approximately 66,000 entries.  Unfortunately, unless I set the tomcat JVM to use a heap size of at least 256M, this velocity template throws an OutOfMemoryException when it is being processed.
> > > > >
> > > > > Any suggestions?
> > > > >
> > > > > Thanks.
> > > > >
> > > > > -L
> > > > >
> > > > > ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > > > > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> > > > >
> > > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> > > 
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> > > 
> > >
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: OutOfMemoryException Processing Velocity Template

Posted by la...@marchex.com.
I tried putting static HTML in the #foreach loop, same problem.  Then I tried setting the large list as a "local" varible:

#set ($localList = $List)
#foreach($row in $localList)
...

but that didnt help either.   I don't see why velocity should use 250+ MB of memory iterating over a list ~8MB in size...  

-L

On Thu, May 05, 2005 at 02:56:28PM -0700, jian chen wrote:
> Well, I don't have a good clue now. 
> 
> What about do the debugging step by step, i.e., use just static html
> in your #foreach loop? Will that blow up the memory?
> 
> Cheers,
> 
> Jian
> 
> 
> 
> On 5/5/05, lawrence@marchex.com <la...@marchex.com> wrote:
> > Thanks for the suggestion.   I tried putting that, along with
> > 
> > file.resource.loader.cache = true
> > 
> > in my velocity.properties file.   Both did not work.   Any other suggestions?
> > 
> > Thanks!
> > 
> > -L
> > 
> > On Thu, May 05, 2005 at 02:11:28PM -0700, jian chen wrote:
> > > Hi,
> > >
> > > This maybe because you haven't turned on template caching. I had
> > > similar problem before, and even if I only used evaluate(...) method
> > > and load the template using my own java program, it happened when the
> > > for loop is lot of iterations.
> > >
> > > The bottom line for my problem is I need to turn on template caching,
> > > so, velocity will not try to cache the objects it parsed during each
> > > time of the iteration.
> > >
> > > I did:
> > > ri.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, "true");
> > >
> > > where ri is a runtime instance.
> > >
> > > Will this fix your issue?
> > >
> > > Cheers,
> > >
> > > Jian
> > >
> > >
> > > On 5/5/05, lawrence@marchex.com <la...@marchex.com> wrote:
> > > > I am getting an OutOfMemoryException:
> > > >
> > > > org.apache.velocity.exception.MethodInvocationException: Invocation of method 'get' in  class org.apache.velocity.tools.struts.TilesTool threw exception class java.lang.OutOfMemoryError : null
> > > >
> > > > when I am creating a large velocity file.  The vm file itself is fairly small, but this piece of velocity is causing the exception:
> > > >
> > > > #foreach($row in $List)
> > > > <tr>
> > > > <td height="20" class="tbltxt">$!row.item1</td>
> > > > <td class="tbltxt">$!row.item2</td>
> > > > <td class="tbltxt">$!row.item3</td>
> > > > <td class="tbltxt">$!row.item4</td>
> > > > <td class="tbltxt">$!number.format('currency', $!row.item5)</td>
> > > > </tr>
> > > > #end
> > > >
> > > > List is a list of relatively small objects (5-6 Strings, a couple of BigDecimals), but the List itself contains approximately 66,000 entries.  Unfortunately, unless I set the tomcat JVM to use a heap size of at least 256M, this velocity template throws an OutOfMemoryException when it is being processed.
> > > >
> > > > Any suggestions?
> > > >
> > > > Thanks.
> > > >
> > > > -L
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> > 
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: OutOfMemoryException Processing Velocity Template

Posted by jian chen <ch...@gmail.com>.
Well, I don't have a good clue now. 

What about do the debugging step by step, i.e., use just static html
in your #foreach loop? Will that blow up the memory?

Cheers,

Jian



On 5/5/05, lawrence@marchex.com <la...@marchex.com> wrote:
> Thanks for the suggestion.   I tried putting that, along with
> 
> file.resource.loader.cache = true
> 
> in my velocity.properties file.   Both did not work.   Any other suggestions?
> 
> Thanks!
> 
> -L
> 
> On Thu, May 05, 2005 at 02:11:28PM -0700, jian chen wrote:
> > Hi,
> >
> > This maybe because you haven't turned on template caching. I had
> > similar problem before, and even if I only used evaluate(...) method
> > and load the template using my own java program, it happened when the
> > for loop is lot of iterations.
> >
> > The bottom line for my problem is I need to turn on template caching,
> > so, velocity will not try to cache the objects it parsed during each
> > time of the iteration.
> >
> > I did:
> > ri.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, "true");
> >
> > where ri is a runtime instance.
> >
> > Will this fix your issue?
> >
> > Cheers,
> >
> > Jian
> >
> >
> > On 5/5/05, lawrence@marchex.com <la...@marchex.com> wrote:
> > > I am getting an OutOfMemoryException:
> > >
> > > org.apache.velocity.exception.MethodInvocationException: Invocation of method 'get' in  class org.apache.velocity.tools.struts.TilesTool threw exception class java.lang.OutOfMemoryError : null
> > >
> > > when I am creating a large velocity file.  The vm file itself is fairly small, but this piece of velocity is causing the exception:
> > >
> > > #foreach($row in $List)
> > > <tr>
> > > <td height="20" class="tbltxt">$!row.item1</td>
> > > <td class="tbltxt">$!row.item2</td>
> > > <td class="tbltxt">$!row.item3</td>
> > > <td class="tbltxt">$!row.item4</td>
> > > <td class="tbltxt">$!number.format('currency', $!row.item5)</td>
> > > </tr>
> > > #end
> > >
> > > List is a list of relatively small objects (5-6 Strings, a couple of BigDecimals), but the List itself contains approximately 66,000 entries.  Unfortunately, unless I set the tomcat JVM to use a heap size of at least 256M, this velocity template throws an OutOfMemoryException when it is being processed.
> > >
> > > Any suggestions?
> > >
> > > Thanks.
> > >
> > > -L
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: OutOfMemoryException Processing Velocity Template

Posted by la...@marchex.com.
Thanks for the suggestion.   I tried putting that, along with 

file.resource.loader.cache = true 

in my velocity.properties file.   Both did not work.   Any other suggestions?  

Thanks!

-L

On Thu, May 05, 2005 at 02:11:28PM -0700, jian chen wrote:
> Hi,
> 
> This maybe because you haven't turned on template caching. I had
> similar problem before, and even if I only used evaluate(...) method
> and load the template using my own java program, it happened when the
> for loop is lot of iterations.
> 
> The bottom line for my problem is I need to turn on template caching,
> so, velocity will not try to cache the objects it parsed during each
> time of the iteration.
> 
> I did:
> ri.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, "true");
> 
> where ri is a runtime instance. 
> 
> Will this fix your issue?
> 
> Cheers,
> 
> Jian
> 
> 
> On 5/5/05, lawrence@marchex.com <la...@marchex.com> wrote:
> > I am getting an OutOfMemoryException:
> > 
> > org.apache.velocity.exception.MethodInvocationException: Invocation of method 'get' in  class org.apache.velocity.tools.struts.TilesTool threw exception class java.lang.OutOfMemoryError : null
> > 
> > when I am creating a large velocity file.  The vm file itself is fairly small, but this piece of velocity is causing the exception:
> > 
> > #foreach($row in $List)
> > <tr>
> > <td height="20" class="tbltxt">$!row.item1</td>
> > <td class="tbltxt">$!row.item2</td>
> > <td class="tbltxt">$!row.item3</td>
> > <td class="tbltxt">$!row.item4</td>
> > <td class="tbltxt">$!number.format('currency', $!row.item5)</td>
> > </tr>
> > #end
> > 
> > List is a list of relatively small objects (5-6 Strings, a couple of BigDecimals), but the List itself contains approximately 66,000 entries.  Unfortunately, unless I set the tomcat JVM to use a heap size of at least 256M, this velocity template throws an OutOfMemoryException when it is being processed.
> > 
> > Any suggestions?
> > 
> > Thanks.
> > 
> > -L
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> > 
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: OutOfMemoryException Processing Velocity Template

Posted by jian chen <ch...@gmail.com>.
Hi,

This maybe because you haven't turned on template caching. I had
similar problem before, and even if I only used evaluate(...) method
and load the template using my own java program, it happened when the
for loop is lot of iterations.

The bottom line for my problem is I need to turn on template caching,
so, velocity will not try to cache the objects it parsed during each
time of the iteration.

I did:
ri.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, "true");

where ri is a runtime instance. 

Will this fix your issue?

Cheers,

Jian


On 5/5/05, lawrence@marchex.com <la...@marchex.com> wrote:
> I am getting an OutOfMemoryException:
> 
> org.apache.velocity.exception.MethodInvocationException: Invocation of method 'get' in  class org.apache.velocity.tools.struts.TilesTool threw exception class java.lang.OutOfMemoryError : null
> 
> when I am creating a large velocity file.  The vm file itself is fairly small, but this piece of velocity is causing the exception:
> 
> #foreach($row in $List)
> <tr>
> <td height="20" class="tbltxt">$!row.item1</td>
> <td class="tbltxt">$!row.item2</td>
> <td class="tbltxt">$!row.item3</td>
> <td class="tbltxt">$!row.item4</td>
> <td class="tbltxt">$!number.format('currency', $!row.item5)</td>
> </tr>
> #end
> 
> List is a list of relatively small objects (5-6 Strings, a couple of BigDecimals), but the List itself contains approximately 66,000 entries.  Unfortunately, unless I set the tomcat JVM to use a heap size of at least 256M, this velocity template throws an OutOfMemoryException when it is being processed.
> 
> Any suggestions?
> 
> Thanks.
> 
> -L
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org