我在寫一個使用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