views:

113

answers:

2

Hi, guys i'm new and i'm not english. I have a problem with using js setInterval that simulate a user click, every X seconds, on submit button. In the page there is only one h:form and h:commandButton. I use a profiler and i see that the java.util.HashMap increase continuosly it's size. After some hours the used heap size is growed a lot respect the start point.

Please help me, this problem make me crazy.

This is the code:

<?xml version = "1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"&gt;
    <h:head>
        <script type="text/javascript">
            var timeoutId = window.setInterval( "userClick()" , 1000 );
        </script>
    </h:head>
    <h:body>
    <h:panelGroup id="testo">test</h:panelGroup>
    <h:form prependId="false" >
        <h:commandButton id="buttonId"
                         action="null"
                         value="Invia">
            <f:ajax event="click" execute="@form" render=":testo"/>
        </h:commandButton>
    </h:form>
    <script type="text/javascript">
    function userClick()
    {
        document.getElementById('buttonId').click();
    }
    </script>
    </h:body>
</html>

Update: After 1 days the application crash again. Now I have used only the setInterval but i have the heapDump generated by glassfish this is the screenshot but i'm unable to post it because my reputation is too low. however java.lang.Object[] consume 20% of heap, java.util.HashMap$Entry[]18% and HashMap 10% Any idea?

Update: Hi, guys i have solved my problem and have found a bug in CDI dependency/injection. I have solved my problem changing the Annotation @Named with @ManagedBean and this solve my problem. In the example i have omitted the code because i think that CDI haven't bug. Obviously the Bean annotated with @Named have request Scoped while the ApplicationScoped Bean doesn't produce the bug. I'm relatively new with CDI, so where i must report the bug?

A: 

After some hours the used heap size is growed a lot respect the start point.

Ok. But what memory usage do you get after garbage collection (GC)? I suggest turning on GC logging (-Xloggc:file.log) and maybe post some graph of the results here. Also make sure you're using a up to date version of GlassFish (3.0.1).

Pascal Thivent
So without setInterval the HasMap used Memory increase of 40 Bytes each 10 seconds while with setInterval the memory increase of about 2Kb each 10 seconds.
Roberto de Santis
@user451960 The problem is not really the `setInterval`, the problem is what actually occur on the server side when the particular request triggered every second is performed.
Pascal Thivent
However i'm doing a simple chat application and i'm using Primefaces p:poll (it use setInterval) for updating the data.When i tested the application with users the application crash in outOfMemory after some hours. So without change in the code i have used Icefaces Push almost of setInterval. Now the application never crash. So I'm sure that setInterval is the problem.
Roberto de Santis
@user451960 You need to look at the resulting difference from the server point of view.
Pascal Thivent
I'm not an expert programmer, it's difficult to understand what may cause this problem.Now i'm trying to use setInterval without using the p:poll primefaces component. However i turn on the GC logging.Thx for the suggest
Roberto de Santis
@user: `setInterval()` is a JavaScript thingie which runs at the webbrowser and has absolutely no influence on webserver memory. It's the Java/JSF code logic running at the webserver which is causing the problems. As now it appears that server side logic which is listening on polls of Primefaces `p:poll` is the cause of the problem. How about Primefaces `p:push`? I'd suggest to report this issue to Primefaces guys.
BalusC
p:push may be a solution (except athmosphere problem with glassfish), but i prefer icefaces push that work great. The problem of icefaces push is the connection timeout that however I set it in my web.xml is ignored (i need to report it too). I'm relatively new about primefaces so initially i think that the memory leaks was caused by my codes. In these day i think to report it to primefaces forum. With jsf 2.0 and primefaces i use Spring too but when i delete p:poll the problem is solved so i think that Spring doesn't make diference
Roberto de Santis
A: 

(moved update back into question, you should delete this "answer")

Roberto de Santis