setInterval jsf2.0 glassfish v3 和内存泄漏
伙计们,我是新人,我不是英语。 我在使用 js setInterval 模拟用户每 X 秒单击一次提交按钮时遇到问题。 页面中只有一个h:form和h:commandButton。 我使用分析器,发现 java.util.HashMap 的大小不断增加。 几个小时后,使用的堆大小相对于起始点增长了很多。
请帮助我,这个问题让我抓狂。
这是代码:
<?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">
<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">
<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>
更新:1天后应用程序再次崩溃。 现在我只使用了 setInterval,但我有 glassfish 生成的 heapDump 这是屏幕截图,但我无法发布它,因为我的声誉太低。 然而 java.lang.Object[] 消耗堆的 20%,java.util.HashMap$Entry[] 18% 和 HashMap 10% 有什么想法吗?
更新: 大家好,我已经解决了我的问题,并发现了 CDI 依赖/注入中的错误。 我已经解决了用 @ManagedBean 更改注释 @Named 的问题,这解决了我的问题。 在示例中,我省略了代码,因为我认为 CDI 没有错误。 显然,用@Named注释的Bean具有请求范围,而ApplicationScoped Bean不会产生错误。 我对 CDI 比较陌生,那么我必须在哪里报告错误?
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">
<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">
<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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的。但是垃圾回收 (GC) 后的内存使用量是多少?我建议打开 GC 日志记录 (
-Xloggc:file.log
),并可能在此处发布一些结果图。另请确保您使用的是最新版本的 GlassFish (3.0.1)。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).