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/[EMAIL PROTECTED]). 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problems with Overloaded Methods
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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: OutOfMemoryException Processing Velocity Template
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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problems with Overloaded Methods
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 [EMAIL PROTECTED] To: Velocity Users List velocity-user@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/[EMAIL PROTECTED]). 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: OutOfMemoryException Processing Velocity Template
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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: OutOfMemoryException Processing Velocity Template
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, [EMAIL PROTECTED] 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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: OutOfMemoryException Processing Velocity Template
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 [EMAIL PROTECTED] 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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] . - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: OutOfMemoryException Processing Velocity Template
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 [EMAIL PROTECTED] 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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] . - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Ifnotnull
Hi jeichels, I had previously upgraded to 1.5-dev and things are working well with the one email templating thing I had found help here on. Since the upgrade, however, I seem to be getting some RHS of #set statement is null. things i don't remember getting before. I explored a bit and found: http://wiki.apache.org/jakarta-velocity/CheckingForNull I added these to my velocity property file: userdirective = org.apache.velocity.tools.generic.directive.Ifnull userdirective = org.apache.velocity.tools.generic.directive.Ifnotnull ## Wow! First person I've heard using it! And changed my template code as follows: #ifnotnull( $form ) #set ($attr = $form.getBean()) #end And get this error: Encountered #end\r\n at line 3, column 1. Was expecting one of: ( ... ... ... ... ... \\ ... ... ... *# ... *# ... ... ... ... ... ... ... ... ... ... ... { ... } ... org.apache.velocity.exception.ParseErrorException: Encountered #end\r\n at line 3, column 1. The error suggests that you aren't configuring the directive correctly. Have you added it to your codebase/classpath? Best regards, -- Shinobu -- Shinobu Kawai [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: OutOfMemoryException Processing Velocity Template
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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] . - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problems with Overloaded Methods
Hi Tim, I noticed that Attila Szegedi (from 2002 - see http://mail-archives.apache.org/mod_mbox/jakarta-velocity-dev/200203.mbox/[EMAIL PROTECTED]). 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=75625view=log Best regards, -- Shinobu -- Shinobu Kawai [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: VelocityViewServlet and mime-mapping in web.xml
i've never used the web.xml mime-setting stuff much and don't know much about it. i suggest you try to override the setContentType method in your subclass to set the file type according to the requested file's extension. On 5/6/05, Chris Searle [EMAIL PROTECTED] wrote: Was reading thru the list/google - since we needed a non-singleton version of VVS. So - the following is using Velocity tools from subversion as of today 6. may. While reading I found some articles where it suggested to use mime-mappings instead of overriding the VelocityViewServlet for each mime-type and overriding the setContentType method for each. Makes sense to me - three servlets - one. Have the following sections in web.xml: servlet servlet-nameVelocityView/servlet-name display-nameVelocityView/display-name servlet-classno.empolis.servlet.VelocityView/servlet-class load-on-startup2/load-on-startup /servlet servlet-mapping servlet-nameVelocityView/servlet-name url-pattern*.vm/url-pattern /servlet-mapping servlet-mapping servlet-nameVelocityView/servlet-name url-pattern*.txt/url-pattern /servlet-mapping servlet-mapping servlet-nameVelocityView/servlet-name url-pattern*.css/url-pattern /servlet-mapping mime-mapping extension.txt/extension mime-typetext/plain/mime-type /mime-mapping mime-mapping extension.css/extension mime-typetext/css/mime-type /mime-mapping mime-mapping extension.vm/extension mime-typetext/html/mime-type /mime-mapping Note - the custom servlet VelocityView simply overrides the doRequest method - looks at the IP address of the request and sets a value in the http session object then calls super.doRequest() - nothing about Content Type. One particular internal machine needs a different view than all the others :) Now - without the mime-mapping section - any .vm files are returned as text/plain (they are normally called via the struts servlet framework). With the mime-mapping section - the .vm files are returned as text/html - and therefore render in the browser. However - the css files (which are called directly - not thru the struts framework) also return as text/html - not text/css. The content is correctly parsed by velocity - it's just the content type that is wrong. What have I misunderstood here - is this not the correct way to use the mime-mappings settings? Should this work with VVS? -- Chris Searle - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problems with Overloaded Methods
Hi Tim, I noticed that Attila Szegedi (from 2002 - see http://mail-archives.apache.org/mod_mbox/jakarta-velocity-dev/200203.mbox/[EMAIL PROTECTED]). 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 [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: OutOfMemoryException Processing Velocity Template
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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -
RE: OutOfMemoryException Processing Velocity Template
Why do you use StringWriter? That is cached in the memory. How big is the StringWriter after the merge? David -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, May 06, 2005 1:22 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template 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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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: [EMAIL PROTECTED] For additional
Re: OutOfMemoryException Processing Velocity Template
I printed out the available memory before and after I call mergeTemplate: Free memory before merge: 217393352 Free memory after merge: 16271392 so I would assume the StringWriter is approximately 200MB after the merge. What should I use/do instead? -Lawrence On Fri, May 06, 2005 at 01:43:50PM -0700, David You wrote: Why do you use StringWriter? That is cached in the memory. How big is the StringWriter after the merge? David -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, May 06, 2005 1:22 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template 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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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
Re: Ifnotnull
I like velocity very much, but I do not like its handling of null in general. I do not want to have to put a isNull check into every object being checked. This at least seems a somewhat straight forward directive. I am not sure how efficient it is in comparison to the other methods of checking and efficiency is important always. In terms of configuring, I have very recent Velocity and Velocity Tools from Subversion. Besides that, all I did was do what the link directed me to do which was to put in those two properties in the velocity.properties file. Should I do something else? If so maybe the document should be updated? Also maybe you can mention something on performance and whether this is a good way to go about it all. There were like five ways mentioned. JohnE - Original Message - From: Shinobu Kawai [EMAIL PROTECTED] Date: Friday, May 6, 2005 2:40 pm Subject: Re: Ifnotnull Hi jeichels, I had previously upgraded to 1.5-dev and things are working well with the one email templating thing I had found help here on. Since the upgrade, however, I seem to be getting some RHS of #set statement is null. things i don't remember getting before. I explored a bit and found: http://wiki.apache.org/jakarta- velocity/CheckingForNull I added these to my velocity property file: userdirective = org.apache.velocity.tools.generic.directive.Ifnull userdirective = org.apache.velocity.tools.generic.directive.Ifnotnull ## Wow! First person I've heard using it! And changed my template code as follows: #ifnotnull( $form ) #set ($attr = $form.getBean()) #end And get this error: Encountered #end\r\n at line 3, column 1. Was expecting one of: ( ... ... ... ... ... \\ ... ... ... *# ... *# ... ... ... ... ... ... ... ... ... ... ... { ... } ... org.apache.velocity.exception.ParseErrorException: Encountered #end\r\n at line 3, column 1. The error suggests that you aren't configuring the directive correctly. Have you added it to your codebase/classpath? Best regards, -- Shinobu -- Shinobu Kawai [EMAIL PROTECTED] --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: OutOfMemoryException Processing Velocity Template
Well, Open a file, use a FileWriter. David -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, May 06, 2005 1:48 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template I printed out the available memory before and after I call mergeTemplate: Free memory before merge: 217393352 Free memory after merge: 16271392 so I would assume the StringWriter is approximately 200MB after the merge. What should I use/do instead? -Lawrence On Fri, May 06, 2005 at 01:43:50PM -0700, David You wrote: Why do you use StringWriter? That is cached in the memory. How big is the StringWriter after the merge? David -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, May 06, 2005 1:22 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template 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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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
Re: OutOfMemoryException Processing Velocity Template
Alright, I changed the Writer to be: OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(test.html)); And this fixes the memory problem. However, my application is running Velocity as a servlet, how should I extend the VelocityServlet to use an OutputStreamWriter intead of a StringWriter? Should I post a different email thread about this? -L On Fri, May 06, 2005 at 01:59:19PM -0700, David You wrote: Well, Open a file, use a FileWriter. David -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, May 06, 2005 1:48 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template I printed out the available memory before and after I call mergeTemplate: Free memory before merge: 217393352 Free memory after merge: 16271392 so I would assume the StringWriter is approximately 200MB after the merge. What should I use/do instead? -Lawrence On Fri, May 06, 2005 at 01:43:50PM -0700, David You wrote: Why do you use StringWriter? That is cached in the memory. How big is the StringWriter after the merge? David -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, May 06, 2005 1:22 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template 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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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);
Re: Ifnotnull
Hi JohnE, I like velocity very much, but I do not like its handling of null in general. I do not want to have to put a isNull check into every object being checked. This at least seems a somewhat straight forward directive. I am not sure how efficient it is in comparison to the other methods of checking and efficiency is important always. Performance never bugged me, but any benchmarks results are welcome. :) In terms of configuring, I have very recent Velocity and Velocity Tools from Subversion. Besides that, all I did was do what the link directed me to do which was to put in those two properties in the velocity.properties file. Should I do something else? If so maybe the document should be updated? You need to actually compile the directive and put it in your class path. It's not part of VelocityTools. http://wiki.apache.org/jakarta-velocity/IfNullDirective http://wiki.apache.org/jakarta-velocity/IfNotNullDirective Also maybe you can mention something on performance and whether this is a good way to go about it all. There were like five ways mentioned. As I said, performance never bugged me, but my otherwise comments are written in the Note:s for each approach. In your case, I think approach #1 might do best. #if( $form ) #set ($attr = $form.getBean()) #end Best regards, -- Shinobu -- Shinobu Kawai [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: OutOfMemoryException Processing Velocity Template
This is why I'm so confused. I wouldn't expect it to use so much memory. What I did to test the memory usage was: System.out.println(Free memory before merge: + Runtime.getRuntime().freeMemory()); Velocity.mergeTemplate(/myfile.vm, ISO-8859-1, context, w ); System.out.println(Free memory after merge: + Runtime.getRuntime().freeMemory()); And then setting the JVM to -Xms256M and -Xmx256M. When I use a String writer, the free memory is reduced by ~200MB. When I use an OutputStreamWriter, it is reduced ~13MB, a huge difference. BTW, I am using 1.4.2_05 -L On Fri, May 06, 2005 at 02:22:01PM -0700, Will Glass-Husain wrote: Hi Lawrence, I got interested, and just ran some similar code with JProfiler looking at VM memory usage. I created a list of 60,000 objects, each with 10 100char columns. Then I used StringWriter to merge as you did. The VM used 3MB at the start, 6.5 MB after creating the list, and 25 after merging. (before I closed the writer). Nowhere close to 200. So perhaps there's something else going on. Although if the problem is one with StringWriter, a lot may depend on the specific JVM you're using. (I'm using Sun 1.4.2_04-b05). WILL - Original Message - From: [EMAIL PROTECTED] To: Velocity Users List velocity-user@jakarta.apache.org Sent: Friday, May 06, 2005 2:08 PM Subject: Re: OutOfMemoryException Processing Velocity Template Ok now I'm confused (suprise, suprise!). I looked at the source for VelocityServlet, and mergeTemplate has: vw = (VelocityWriter) writerPool.get(); if (vw == null) { vw = new VelocityWriter(new OutputStreamWriter(output, encoding),4 * 1024, true); } else { vw.recycle(new OutputStreamWriter(output, encoding)); } template.merge(context, vw); === So the VelocityServlet DOES use OutputStreamWriter already ... so then why does it still utilize so much memory? -L On Fri, May 06, 2005 at 02:02:07PM -0700, [EMAIL PROTECTED] wrote: Alright, I changed the Writer to be: OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(test.html)); And this fixes the memory problem. However, my application is running Velocity as a servlet, how should I extend the VelocityServlet to use an OutputStreamWriter intead of a StringWriter? Should I post a different email thread about this? -L On Fri, May 06, 2005 at 01:59:19PM -0700, David You wrote: Well, Open a file, use a FileWriter. David -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, May 06, 2005 1:48 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template I printed out the available memory before and after I call mergeTemplate: Free memory before merge: 217393352 Free memory after merge: 16271392 so I would assume the StringWriter is approximately 200MB after the merge. What should I use/do instead? -Lawrence On Fri, May 06, 2005 at 01:43:50PM -0700, David You wrote: Why do you use StringWriter? That is cached in the memory. How big is the StringWriter after the merge? David -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, May 06, 2005 1:22 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template 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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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
Re: OutOfMemoryException Processing Velocity Template
You might consider trying a profiler. Most of them have trial version available. This could tell you exactly where the memory is going. I just bought JProfiler, and it seems a bit better priced than the others. Here's a user review: http://www.jlamp.com/blog/2005/02/01/1107280975000.html You might also check out Hyades from the Eclipse project for an open source option. WILL - Original Message - From: [EMAIL PROTECTED] To: Velocity Users List velocity-user@jakarta.apache.org Sent: Friday, May 06, 2005 2:39 PM Subject: Re: OutOfMemoryException Processing Velocity Template This is why I'm so confused. I wouldn't expect it to use so much memory. What I did to test the memory usage was: System.out.println(Free memory before merge: + Runtime.getRuntime().freeMemory()); Velocity.mergeTemplate(/myfile.vm, ISO-8859-1, context, w ); System.out.println(Free memory after merge: + Runtime.getRuntime().freeMemory()); And then setting the JVM to -Xms256M and -Xmx256M. When I use a String writer, the free memory is reduced by ~200MB. When I use an OutputStreamWriter, it is reduced ~13MB, a huge difference. BTW, I am using 1.4.2_05 -L On Fri, May 06, 2005 at 02:22:01PM -0700, Will Glass-Husain wrote: Hi Lawrence, I got interested, and just ran some similar code with JProfiler looking at VM memory usage. I created a list of 60,000 objects, each with 10 100char columns. Then I used StringWriter to merge as you did. The VM used 3MB at the start, 6.5 MB after creating the list, and 25 after merging. (before I closed the writer). Nowhere close to 200. So perhaps there's something else going on. Although if the problem is one with StringWriter, a lot may depend on the specific JVM you're using. (I'm using Sun 1.4.2_04-b05). WILL - Original Message - From: [EMAIL PROTECTED] To: Velocity Users List velocity-user@jakarta.apache.org Sent: Friday, May 06, 2005 2:08 PM Subject: Re: OutOfMemoryException Processing Velocity Template Ok now I'm confused (suprise, suprise!). I looked at the source for VelocityServlet, and mergeTemplate has: vw = (VelocityWriter) writerPool.get(); if (vw == null) { vw = new VelocityWriter(new OutputStreamWriter(output, encoding),4 * 1024, true); } else { vw.recycle(new OutputStreamWriter(output, encoding)); } template.merge(context, vw); === So the VelocityServlet DOES use OutputStreamWriter already ... so then why does it still utilize so much memory? -L On Fri, May 06, 2005 at 02:02:07PM -0700, [EMAIL PROTECTED] wrote: Alright, I changed the Writer to be: OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(test.html)); And this fixes the memory problem. However, my application is running Velocity as a servlet, how should I extend the VelocityServlet to use an OutputStreamWriter intead of a StringWriter? Should I post a different email thread about this? -L On Fri, May 06, 2005 at 01:59:19PM -0700, David You wrote: Well, Open a file, use a FileWriter. David -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, May 06, 2005 1:48 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template I printed out the available memory before and after I call mergeTemplate: Free memory before merge: 217393352 Free memory after merge: 16271392 so I would assume the StringWriter is approximately 200MB after the merge. What should I use/do instead? -Lawrence On Fri, May 06, 2005 at 01:43:50PM -0700, David You wrote: Why do you use StringWriter? That is cached in the memory. How big is the StringWriter after the merge? David -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, May 06, 2005 1:22 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template 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
Re: OutOfMemoryException Processing Velocity Template
Ok I tried using JProfiler and used a StringWriter, and found that the item that was taking the most memory (150 MB) was. char[]! Ok now I'm completely stumped and clueless. -L On Fri, May 06, 2005 at 02:51:15PM -0700, Will Glass-Husain wrote: You might consider trying a profiler. Most of them have trial version available. This could tell you exactly where the memory is going. I just bought JProfiler, and it seems a bit better priced than the others. Here's a user review: http://www.jlamp.com/blog/2005/02/01/1107280975000.html You might also check out Hyades from the Eclipse project for an open source option. WILL - Original Message - From: [EMAIL PROTECTED] To: Velocity Users List velocity-user@jakarta.apache.org Sent: Friday, May 06, 2005 2:39 PM Subject: Re: OutOfMemoryException Processing Velocity Template This is why I'm so confused. I wouldn't expect it to use so much memory. What I did to test the memory usage was: System.out.println(Free memory before merge: + Runtime.getRuntime().freeMemory()); Velocity.mergeTemplate(/myfile.vm, ISO-8859-1, context, w ); System.out.println(Free memory after merge: + Runtime.getRuntime().freeMemory()); And then setting the JVM to -Xms256M and -Xmx256M. When I use a String writer, the free memory is reduced by ~200MB. When I use an OutputStreamWriter, it is reduced ~13MB, a huge difference. BTW, I am using 1.4.2_05 -L On Fri, May 06, 2005 at 02:22:01PM -0700, Will Glass-Husain wrote: Hi Lawrence, I got interested, and just ran some similar code with JProfiler looking at VM memory usage. I created a list of 60,000 objects, each with 10 100char columns. Then I used StringWriter to merge as you did. The VM used 3MB at the start, 6.5 MB after creating the list, and 25 after merging. (before I closed the writer). Nowhere close to 200. So perhaps there's something else going on. Although if the problem is one with StringWriter, a lot may depend on the specific JVM you're using. (I'm using Sun 1.4.2_04-b05). WILL - Original Message - From: [EMAIL PROTECTED] To: Velocity Users List velocity-user@jakarta.apache.org Sent: Friday, May 06, 2005 2:08 PM Subject: Re: OutOfMemoryException Processing Velocity Template Ok now I'm confused (suprise, suprise!). I looked at the source for VelocityServlet, and mergeTemplate has: vw = (VelocityWriter) writerPool.get(); if (vw == null) { vw = new VelocityWriter(new OutputStreamWriter(output, encoding),4 * 1024, true); } else { vw.recycle(new OutputStreamWriter(output, encoding)); } template.merge(context, vw); === So the VelocityServlet DOES use OutputStreamWriter already ... so then why does it still utilize so much memory? -L On Fri, May 06, 2005 at 02:02:07PM -0700, [EMAIL PROTECTED] wrote: Alright, I changed the Writer to be: OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(test.html)); And this fixes the memory problem. However, my application is running Velocity as a servlet, how should I extend the VelocityServlet to use an OutputStreamWriter intead of a StringWriter? Should I post a different email thread about this? -L On Fri, May 06, 2005 at 01:59:19PM -0700, David You wrote: Well, Open a file, use a FileWriter. David -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, May 06, 2005 1:48 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template I printed out the available memory before and after I call mergeTemplate: Free memory before merge: 217393352 Free memory after merge: 16271392 so I would assume the StringWriter is approximately 200MB after the merge. What should I use/do instead? -Lawrence On Fri, May 06, 2005 at 01:43:50PM -0700, David You wrote: Why do you use StringWriter? That is cached in the memory. How big is the StringWriter after the merge? David -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, May 06, 2005 1:22 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template 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 */ }
Re: OutOfMemoryException Processing Velocity Template
Yes, but which ones? The char[] in the StringWriter, the char[] in the Template object, or the char[] in the strings in your original objects? That would be useful info. WILL - Original Message - From: [EMAIL PROTECTED] To: Velocity Users List velocity-user@jakarta.apache.org Sent: Friday, May 06, 2005 3:45 PM Subject: Re: OutOfMemoryException Processing Velocity Template Ok I tried using JProfiler and used a StringWriter, and found that the item that was taking the most memory (150 MB) was. char[]! Ok now I'm completely stumped and clueless. -L On Fri, May 06, 2005 at 02:51:15PM -0700, Will Glass-Husain wrote: You might consider trying a profiler. Most of them have trial version available. This could tell you exactly where the memory is going. I just bought JProfiler, and it seems a bit better priced than the others. Here's a user review: http://www.jlamp.com/blog/2005/02/01/1107280975000.html You might also check out Hyades from the Eclipse project for an open source option. WILL - Original Message - From: [EMAIL PROTECTED] To: Velocity Users List velocity-user@jakarta.apache.org Sent: Friday, May 06, 2005 2:39 PM Subject: Re: OutOfMemoryException Processing Velocity Template This is why I'm so confused. I wouldn't expect it to use so much memory. What I did to test the memory usage was: System.out.println(Free memory before merge: + Runtime.getRuntime().freeMemory()); Velocity.mergeTemplate(/myfile.vm, ISO-8859-1, context, w ); System.out.println(Free memory after merge: + Runtime.getRuntime().freeMemory()); And then setting the JVM to -Xms256M and -Xmx256M. When I use a String writer, the free memory is reduced by ~200MB. When I use an OutputStreamWriter, it is reduced ~13MB, a huge difference. BTW, I am using 1.4.2_05 -L On Fri, May 06, 2005 at 02:22:01PM -0700, Will Glass-Husain wrote: Hi Lawrence, I got interested, and just ran some similar code with JProfiler looking at VM memory usage. I created a list of 60,000 objects, each with 10 100char columns. Then I used StringWriter to merge as you did. The VM used 3MB at the start, 6.5 MB after creating the list, and 25 after merging. (before I closed the writer). Nowhere close to 200. So perhaps there's something else going on. Although if the problem is one with StringWriter, a lot may depend on the specific JVM you're using. (I'm using Sun 1.4.2_04-b05). WILL - Original Message - From: [EMAIL PROTECTED] To: Velocity Users List velocity-user@jakarta.apache.org Sent: Friday, May 06, 2005 2:08 PM Subject: Re: OutOfMemoryException Processing Velocity Template Ok now I'm confused (suprise, suprise!). I looked at the source for VelocityServlet, and mergeTemplate has: vw = (VelocityWriter) writerPool.get(); if (vw == null) { vw = new VelocityWriter(new OutputStreamWriter(output, encoding),4 * 1024, true); } else { vw.recycle(new OutputStreamWriter(output, encoding)); } template.merge(context, vw); === So the VelocityServlet DOES use OutputStreamWriter already ... so then why does it still utilize so much memory? -L On Fri, May 06, 2005 at 02:02:07PM -0700, [EMAIL PROTECTED] wrote: Alright, I changed the Writer to be: OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(test.html)); And this fixes the memory problem. However, my application is running Velocity as a servlet, how should I extend the VelocityServlet to use an OutputStreamWriter intead of a StringWriter? Should I post a different email thread about this? -L On Fri, May 06, 2005 at 01:59:19PM -0700, David You wrote: Well, Open a file, use a FileWriter. David -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, May 06, 2005 1:48 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template I printed out the available memory before and after I call mergeTemplate: Free memory before merge: 217393352 Free memory after merge: 16271392 so I would assume the StringWriter is approximately 200MB after the merge. What should I use/do instead? -Lawrence On Fri, May 06, 2005 at 01:43:50PM -0700, David You wrote: Why do you use StringWriter? That is cached in the memory. How big is the StringWriter after the merge? David -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, May 06, 2005 1:22 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template 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 */
Re: Testing Velocity with JUnit.
Hi all, My server has been down for like half an year, so I decided to put all this in the wiki: http://wiki.apache.org/jakarta-velocity/TestingVelocity On 11/9/04, Shinobu Kawai [EMAIL PROTECTED] wrote: Hi all, I'd like to share how I've been testing Velocity with JUnit lately. First, I made a base TestCase class, AbstractVelocityTestCase. http://sylow.no-ip.com/maven/site/ShinobuDemo/xref/org/ieee/shinobu/demo/velocity/AbstractVelocityTestCase.html This class has the properties needed to test VTL: - engine : The VelocityEngine to use for template processing. - template : The VTL String to process. - context : The Context to use when processing the template. - expected : The expected result String. After configuring these properties, I call assertVelocity(), which will process the template and compare it with the expected result. PublicFieldUberspectTest shows an example of the general flow. http://sylow.no-ip.com/maven/site/ShinobuDemo/xref-test/org/apache/velocity/tools/generic/introspection/PublicFieldUberspectTest.html Many other example tests can be found at: http://sylow.no-ip.com/maven/site/ShinobuDemo/xref-test/org/ieee/shinobu/demo/velocity/package-summary.html For testing ViewTools, I have made AbstractVelocityMockStrutsTestCase which uses strutstestcase. http://sylow.no-ip.com/maven/site/ShinobuDemo/xref/org/ieee/shinobu/demo/velocity/AbstractVelocityMockStrutsTestCase.html cf. http://strutstestcase.sourceforge.net/ The flow of testing remains the same. As always, any comments are welcome. :) Best regards, -- Shinobu -- Shinobu Kawai [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: OutOfMemoryException Processing Velocity Template
I remember reading the performance book, which mentioned that Java Writer does not optimize on the Writer. It does not reuse the internal char[] buffer. But that should not overflow, it just makes the GC busier. Regards David -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, May 06, 2005 3:46 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template Ok I tried using JProfiler and used a StringWriter, and found that the item that was taking the most memory (150 MB) was. char[]! Ok now I'm completely stumped and clueless. -L On Fri, May 06, 2005 at 02:51:15PM -0700, Will Glass-Husain wrote: You might consider trying a profiler. Most of them have trial version available. This could tell you exactly where the memory is going. I just bought JProfiler, and it seems a bit better priced than the others. Here's a user review: http://www.jlamp.com/blog/2005/02/01/1107280975000.html You might also check out Hyades from the Eclipse project for an open source option. WILL - Original Message - From: [EMAIL PROTECTED] To: Velocity Users List velocity-user@jakarta.apache.org Sent: Friday, May 06, 2005 2:39 PM Subject: Re: OutOfMemoryException Processing Velocity Template This is why I'm so confused. I wouldn't expect it to use so much memory. What I did to test the memory usage was: System.out.println(Free memory before merge: + Runtime.getRuntime().freeMemory()); Velocity.mergeTemplate(/myfile.vm, ISO-8859-1, context, w ); System.out.println(Free memory after merge: + Runtime.getRuntime().freeMemory()); And then setting the JVM to -Xms256M and -Xmx256M. When I use a String writer, the free memory is reduced by ~200MB. When I use an OutputStreamWriter, it is reduced ~13MB, a huge difference. BTW, I am using 1.4.2_05 -L On Fri, May 06, 2005 at 02:22:01PM -0700, Will Glass-Husain wrote: Hi Lawrence, I got interested, and just ran some similar code with JProfiler looking at VM memory usage. I created a list of 60,000 objects, each with 10 100char columns. Then I used StringWriter to merge as you did. The VM used 3MB at the start, 6.5 MB after creating the list, and 25 after merging. (before I closed the writer). Nowhere close to 200. So perhaps there's something else going on. Although if the problem is one with StringWriter, a lot may depend on the specific JVM you're using. (I'm using Sun 1.4.2_04-b05). WILL - Original Message - From: [EMAIL PROTECTED] To: Velocity Users List velocity-user@jakarta.apache.org Sent: Friday, May 06, 2005 2:08 PM Subject: Re: OutOfMemoryException Processing Velocity Template Ok now I'm confused (suprise, suprise!). I looked at the source for VelocityServlet, and mergeTemplate has: vw = (VelocityWriter) writerPool.get(); if (vw == null) { vw = new VelocityWriter(new OutputStreamWriter(output, encoding),4 * 1024, true); } else { vw.recycle(new OutputStreamWriter(output, encoding)); } template.merge(context, vw); === So the VelocityServlet DOES use OutputStreamWriter already ... so then why does it still utilize so much memory? -L On Fri, May 06, 2005 at 02:02:07PM -0700, [EMAIL PROTECTED] wrote: Alright, I changed the Writer to be: OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(test.html)); And this fixes the memory problem. However, my application is running Velocity as a servlet, how should I extend the VelocityServlet to use an OutputStreamWriter intead of a StringWriter? Should I post a different email thread about this? -L On Fri, May 06, 2005 at 01:59:19PM -0700, David You wrote: Well, Open a file, use a FileWriter. David -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, May 06, 2005 1:48 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template I printed out the available memory before and after I call mergeTemplate: Free memory before merge: 217393352 Free memory after merge: 16271392 so I would assume the StringWriter is approximately 200MB after the merge. What should I use/do instead? -Lawrence On Fri, May 06, 2005 at 01:43:50PM -0700, David You wrote: Why do you use StringWriter? That is cached in the memory. How big is the StringWriter after the merge? David -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, May 06, 2005 1:22 PM To: Velocity Users List Subject: Re: OutOfMemoryException Processing Velocity Template 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 */