我在写一个使用Atmosphere插件的Grails应用程序。这个连接可以工作,但每次我在浏览器中更新页面时,我都会看到我的Web服务器添加了一个新的守护程序线程,这个线程从未被释放。断开Grails中的大气插座
线程数达到200后,Web服务器冻结。
似乎没有文档解释什么是正确的方式来处理与Atmosphere插件的资源(断开连接)?
我的客户端代码执行此操作:
var connectedEndpoint = null;
$(function()
{
function callback(response)
{
if (response.transport != 'polling' && response.state != 'connected' && response.state != 'closed') {
if (response.status == 200) {
eval(response.responseBody);
}
}
}
$.atmosphere.subscribe('${resource(dir: '/atmosphere/channel')}', callback, $.atmosphere.request = {transport: 'streaming'});
connectedEndpoint = $.atmosphere.response;
});
$(window).unload(function()
{
$.atmosphere.unsubscribe();
connectedEndpoint = null;
});
我用在服务器端的气氛的处理程序;
package demo
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
import org.atmosphere.cpr.AtmosphereHandler
import org.atmosphere.cpr.AtmosphereResource;
import org.atmosphere.cpr.AtmosphereResourceEvent;
class DemoController implements AtmosphereHandler<HttpServletRequest, HttpServletResponse> {
@Override
public void destroy() {
println "destroy"
}
@Override
public void onRequest(AtmosphereResource<HttpServletRequest, HttpServletResponse> event) throws IOException
{
event.suspend()
}
@Override
public void onStateChange(AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event) throws IOException
{
if (event.isSuspended())
{
event.resource.response.writer.with {
def message = event.message
write "set${message.paramName}(\"${message.id}\",\"${message.value}\");"
flush()
}
}
}
}
处理程序的destroy
功能不会被调用!
下图显示我有23个线程在运行。当我开始我的应用程序时,其中大约有6个,每次按F5时都会添加它们!如果我禁用大气新线程不添加,所以这个问题是与大气有关。 (我在Windows7上使用SpringSource工具套件)。
如果溶液是不平凡的我希望详细的一步一步的指示或一个例子。
UPDATE:部署在Tomcat中我有以下每个错误超过20秒:
Apr 02, 2012 2:35:15 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor host-manager.xml
Apr 02, 2012 2:35:16 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor manager.xml
Apr 02, 2012 2:35:16 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory docs
Apr 02, 2012 2:35:16 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory examples
Apr 02, 2012 2:35:17 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory ROOT
Apr 02, 2012 2:35:17 PM org.apache.coyote.http11.Http11AprProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Apr 02, 2012 2:35:17 PM org.apache.coyote.ajp.AjpAprProtocol start
INFO: Starting Coyote AJP/1.3 on ajp-8009
Apr 02, 2012 2:35:17 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 11401 ms
2012-04-02 14:41:17,122 [http-8080-39] ERROR cpr.AsynchronousProcessor - failed
to timeout resource AtmosphereResourceImpl{, hasCode-1035775543,
[email protected],
broadcaster=org.atmosphere.cpr.DefaultBroadcaster,
[email protected],
serializer=null,
isInScope=true,
useWriter=true,
listeners=[]}
2012-04-02 14:42:15,034 [http-8080-69] ERROR cpr.AsynchronousProcessor - failed
to timeout resource AtmosphereResourceImpl{, hasCode-58082012,
[email protected],
broadcaster=org.atmosphere.cpr.DefaultBroadcaster,
[email protected],
serializer=null,
isInScope=true,
useWriter=true,
listeners=[]}
2012-04-02 14:44:41,159 [http-8080-13] ERROR cpr.AsynchronousProcessor - failed
to timeout resource AtmosphereResourceImpl{, hasCode648226529,
[email protected],
broadcaster=org.atmosphere.cpr.DefaultBroadcaster,
[email protected],
serializer=null,
isInScope=true,
useWriter=true,
listeners=[]}
....
不幸的是,它不起作用:'没有这样的属性:类:org的maxInactiveActivity。atmosphere.cpr.CometSupport' – conceptacid 2012-03-13 09:19:15
我的web服务器是tomcat。 – conceptacid 2012-03-13 09:23:48