JBOSS默认的钝化时间
D:\DevelopTool\jboss-4.2.2.GA\server\default\conf\standardjboss.xml
查找Standard Stateful SessionBean找到如下:
<container-configuration> <container-name>Standard Stateful SessionBean</container-name> <call-logging>false</call-logging> <invoker-proxy-binding-name>stateful-unified-invoker</invoker-proxy-binding-name> <container-interceptors> <interceptor>org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor</interceptor> <interceptor>org.jboss.ejb.plugins.LogInterceptor</interceptor> <!-- CMT --> <interceptor transaction="Container">org.jboss.ejb.plugins.TxInterceptorCMT</interceptor> <interceptor transaction="Container">org.jboss.ejb.plugins.CallValidationInterceptor</interceptor> <interceptor transaction="Container">org.jboss.ejb.plugins.StatefulSessionInstanceInterceptor</interceptor> <!-- BMT --> <interceptor transaction="Bean">org.jboss.ejb.plugins.StatefulSessionInstanceInterceptor</interceptor> <interceptor transaction="Bean">org.jboss.ejb.plugins.TxInterceptorBMT</interceptor> <interceptor transaction="Bean">org.jboss.ejb.plugins.CallValidationInterceptor</interceptor> <interceptor>org.jboss.resource.connectionmanager.CachedConnectionInterceptor</interceptor> <interceptor>org.jboss.ejb.plugins.SecurityInterceptor</interceptor> </container-interceptors> <instance-cache>org.jboss.ejb.plugins.StatefulSessionInstanceCache</instance-cache> <persistence-manager>org.jboss.ejb.plugins.StatefulSessionFilePersistenceManager</persistence-manager> <container-cache-conf> <cache-policy>org.jboss.ejb.plugins.LRUStatefulContextCachePolicy</cache-policy> <cache-policy-conf> <min-capacity>50</min-capacity> <max-capacity>1000000</max-capacity> <remover-period>1800</remover-period> <max-bean-life>1800</max-bean-life> <overager-period>300</overager-period> <max-bean-age>600</max-bean-age> <resizer-period>400</resizer-period> <max-cache-miss-period>60</max-cache-miss-period> <min-cache-miss-period>1</min-cache-miss-period> <cache-load-factor>0.75</cache-load-factor> </cache-policy-conf> </container-cache-conf> <container-pool-conf> <MaximumSize>100</MaximumSize> </container-pool-conf> </container-configuration>
其中<max-bean-age>600</max-bean-age> 为jboss默认的时间,可以自己修改。EJB服务端代码:package com.persia.ejb; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import javax.ejb.Init; import javax.ejb.PostActivate; import javax.ejb.PrePassivate; import javax.ejb.Remote; import javax.ejb.Remove; import javax.ejb.Stateful; @Stateful @Remote({LifeCycle.class}) public class LifeCycleBean implements LifeCycle { public String Say() { try{ Thread.sleep(1000*30); }catch(InterruptedException e){ e.printStackTrace(); } return "这是会话bean的生命周期示例--调用sleep方法"; } @Init public void initialize(){ System.out.println("@Init--initialize方法被调用"); } @PostConstruct public void construct(){ System.out.println("@PostConstruct--construct方法被调用"); } @PreDestroy public void exit(){ System.out.println("@PreDestroy--exit方法被调用"); } @PrePassivate public void serialize(){ System.out.println("@PrePassive--serialize方法被调用"); } @PostActivate public void activate(){ System.out.println("@PostActivate--activate方法被调用"); } @Remove public void stopSession() { // TODO Auto-generated method stub System.out.println("@Remove---stopSession()被调用"); } }
客户端代码:
<%
Properties props=new Properties();
props.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.provider.url","localhost:1099");
props.setProperty("java.naming.factory.url.pkgs","org.jboss.naming");
InitialContext ctx;
ctx=new InitialContext(props);
try{
LifeCycle lf=(LifeCycle)session.getAttribute("lifecycle");
if(lf==null){
lf=(LifeCycle)ctx.lookup("LifeCycleBean/remote");
session.setAttribute("lifecycle",lf);
}
out.println("客户端调用了say方法");
out.println(lf.Say());
out.println("等待10min后容器将钝化会话bean,prepassivate的serialize将被调用");
out.println("可以执行stopSession,通知容器销毁bean实例,在销毁之前@predestroy的exit方法将被调用");
}
catch(Exception e){
out.println(e.getMessage());
}
%>JBOSS控制台输出:
11:08:17,625 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8080 11:08:17,656 INFO [AjpProtocol] Starting Coyote AJP/1.3 on ajp-127.0.0.1-8009 11:08:17,671 INFO [Server] JBoss (MX MicroKernel) [4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221139)] Started in 24s:421ms 11:09:22,703 INFO [TomcatDeployer] deploy, ctxPath=/LifeCycleClient, warUrl=.../deploy/LifeCycleClient.war/ 11:09:27,796 INFO [TomcatDeployer] undeploy, ctxPath=/LifeCycleClient, warUrl=.../deploy/LifeCycleClient.war/ 11:09:27,843 INFO [TomcatDeployer] deploy, ctxPath=/LifeCycleClient, warUrl=.../deploy/LifeCycleClient.war/ 11:09:48,312 INFO [STDOUT] @Init--initialize方法被调用 11:09:48,328 INFO [STDOUT] @PostConstruct--construct方法被调用 11:17:46,250 ERROR [AjpMessage] Invalid message recieved with signature 18245 11:18:11,875 INFO [STDOUT] @PrePassive--serialize方法被调用
我吃完午饭了,现在是12点了,还没被销毁,难道要手工调用@remove方法,还是销毁时间很长?
如果看<remover-period>1800</remover-period>,应该是30分钟,不过早就过了。
浙公网安备 33010602011771号