Tomcat会话未正确清理

时间:2016-03-11 14:21:20

标签: java session tomcat tomcat7

我们遇到了内存泄漏。只要没有正确清理tomcat会话,就会发生这种情况。我们创建的堆转储之一在会话中显示2.5GB。日志显示以下内容:

2016-03-10 19:32:34,976 INFO ContainerBackgroundProcessor[StandardEngine[Catalina]] de.projekt.application.SessionListener.sessionDestroyed(150) - SESSION_DESTROYED - D50C0D6ADC7A02B71032E729692D3341.tomcat02 IS REMOVED(sessions.size=101)
2016-03-10 19:32:34,977 INFO ContainerBackgroundProcessor[StandardEngine[Catalina]] de.projekt.application.SessionListener.sessionDestroyed(150) - SESSION_DESTROYED - F552AF04CCA3E5987CA12B3CA707A65B.tomcat02 IS REMOVED(sessions.size=100)
2016-03-10 19:33:35,456 INFO ContainerBackgroundProcessor[StandardEngine[Catalina]] de.projekt.application.SessionListener.sessionDestroyed(150) - SESSION_DESTROYED - 9B20DEFCC6AA4B4E83E59D1C9E017EC2.tomcat02 IS REMOVED(sessions.size=99)
2016-03-10 19:33:35,456 INFO ContainerBackgroundProcessor[StandardEngine[Catalina]] de.projekt.application.SessionListener.sessionDestroyed(150) - SESSION_DESTROYED - A56C5E65C5F4230A3699E5B46BEAA5A7.tomcat02 IS REMOVED(sessions.size=98)
2016-03-10 19:33:35,554 INFO ContainerBackgroundProcessor[StandardEngine[Catalina]] de.projekt.application.SessionListener.sessionDestroyed(150) - SESSION_DESTROYED - F7419BD927689F359C4FD9E382CECB35.tomcat02 IS REMOVED(sessions.size=97)
2016-03-10 19:33:35,608 INFO ContainerBackgroundProcessor[StandardEngine[Catalina]] de.projekt.application.SessionListener.sessionDestroyed(150) - SESSION_DESTROYED - 86A2EC35561C2A6F6CC33E9279D8D378.tomcat02 IS REMOVED(sessions.size=96)
2016-03-10 19:33:35,608 INFO ContainerBackgroundProcessor[StandardEngine[Catalina]] de.projekt.application.SessionListener.sessionDestroyed(150) - SESSION_DESTROYED - AFEC9F52D6552569B0D6E3010D0025F7.tomcat02 IS REMOVED(sessions.size=95)
2016-03-10 19:47:39,831 INFO ajp-bio-8010-exec-4652 de.projekt.application.SessionListener.sessionDestroyed(150) - SESSION_DESTROYED - 8177FD469930CC8C58A40E1AC05DDF3D.tomcat02 IS REMOVED(sessions.size=121)
2016-03-10 19:47:51,802 INFO ajp-bio-8010-exec-4671 de.projekt.application.SessionListener.sessionDestroyed(150) - SESSION_DESTROYED - C70F96B181343936D9B763AA8E058462.tomcat02 IS REMOVED(sessions.size=123)
2016-03-10 19:47:52,008 INFO ajp-bio-8010-exec-4672 de.projekt.application.SessionListener.sessionDestroyed(150) - SESSION_DESTROYED - AB5A52D70167AB73B50BC15F38CCC555.tomcat02 IS REMOVED(sessions.size=124)
2016-03-10 19:48:19,638 INFO ajp-bio-8010-exec-4688 de.projekt.application.SessionListener.sessionDestroyed(150) - SESSION_DESTROYED - C1171F663AF81155B033090F6A6526F4.tomcat02 IS REMOVED(sessions.size=124)
2016-03-10 19:50:50,764 INFO ajp-bio-8010-exec-4377 de.projekt.application.SessionListener.sessionDestroyed(150) - SESSION_DESTROYED - A78314AFA1A0864F61FBBC8A3F87DDFC.tomcat02 IS REMOVED(sessions.size=132)
2016-03-10 19:51:12,568 INFO ajp-bio-8010-exec-4555 de.projekt.application.SessionListener.sessionDestroyed(150) - SESSION_DESTROYED - 34ADDDB2CFF705946160B32B0C3A07E8.tomcat02 IS REMOVED(sessions.size=134)
2016-03-10 19:51:15,115 INFO ajp-bio-8010-exec-4533 de.projekt.application.SessionListener.sessionDestroyed(150) - SESSION_DESTROYED - 1697EFBFEE37928D77CB82C403FAAB81.tomcat02 IS REMOVED(sessions.size=134)
2016-03-10 19:51:45,837 INFO ajp-bio-8010-exec-4602 de.projekt.application.SessionListener.sessionDestroyed(150) - SESSION_DESTROYED - BCD0654B34CBEE18AEF8FF72BF13517A.tomcat02 IS REMOVED(sessions.size=139)
2016-03-10 19:53:14,098 INFO ajp-bio-8010-exec-4603 de.projekt.application.SessionListener.sessionDestroyed(150) - SESSION_DESTROYED - 62FCB3CBF8F923F0005BD77CB1658B98.tomcat02 IS REMOVED(sessions.size=159)
2016-03-10 19:58:36,482 INFO ajp-bio-8010-exec-4574 de.projekt.application.SessionListener.sessionDestroyed(150) - SESSION_DESTROYED - 8CD74088FAB550870ECB6242B1A0DEEC.tomcat02 IS REMOVED(sessions.size=194)
2016-03-10 19:58:54,167 INFO ajp-bio-8010-exec-4601 de.projekt.application.SessionListener.sessionDestroyed(150) - SESSION_DESTROYED - FC91875E280724BD1397D4BC7ED80CF8.tomcat02 IS REMOVED(sessions.size=196)
2016-03-10 19:59:04,894 INFO ajp-bio-8010-exec-4709 de.projekt.application.SessionListener.sessionDestroyed(150) - SESSION_DESTROYED - BEF4DF2EDC5217370679B6C9F06D8BA3.tomcat02 IS REMOVED(sessions.size=197)
2016-03-10 19:59:35,716 INFO ajp-bio-8010-exec-4723 de.projekt.application.SessionListener.sessionDestroyed(150) - SESSION_DESTROYED - 0B5CB30250F81D0AFFAA479E13501DD4.tomcat02 IS REMOVED(sessions.size=205) 

...  过了一会儿,我们面对的是大约只有50个用户的2k会话。

2016-03-10 23:59:36,641 INFO ajp-bio-8010-exec-5973 de.projekt.application.SessionListener.sessionDestroyed(150) - SESSION_DESTROYED - 1B086A93D55A748D3E8769A957A06FD0.tomcat02 IS REMOVED(sessions.size=1518)

这些会话的清理工作直到ContainerBackgroundProcessor [StandardEngine [Catalina]]线程调用SessionListener。 突然间,此线程不再调用SessionListener。相反,它被ajp-bio线程调用,会话数量也在增加。

有人可以向我解释为什么ajp-bio线程突然调用SessionListener而不是ContainerBackgroundProcessor [StandardEngine [Catalina]]线程?

目前卡塔利娜没有例外。 tomcat也拥有足够的内存。

- 编辑 -

的web.xml

<session-config>
<session-timeout>30</session-timeout>
<tracking-mode>COOKIE</tracking-mode>
</session-config>

2 个答案:

答案 0 :(得分:0)

您应该配置web.xml,以便会话在指定时间后自动过期。在这种情况下,将没有孤儿会议

答案 1 :(得分:0)

由于会话配置在30分钟后超时,因此您需要测试WebApp并确保1个用户登录时只创建了1个会话。 如果有多个会话,则需要跟踪创建更多会话的代码/实体。 注意:会话可以通过编程方式创建,因此请检查您的代码是否在其他位置执行。