您可以通过实现HttpSessionBindingListener来实现,您需要通过调用来注册一个持有锁的会话
registerSession(字符串“
sessionBindingListener”可能不会更改)。
valueUnbound()在会话超时之后和会话被销毁 之前 ,容器将回调该方法。
public class ObjectLock implements Serializable,HttpSessionBindingListener { public void valueBound(HttpSessionBindingEvent event) { log.info("valueBound:" + event.getName() + " session:" + event.getSession().getId() ); } public void registerSession() { FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put( "sessionBindingListener", this ); log.info( "registered sessionBindingListener" ); } public void valueUnbound(HttpSessionBindingEvent event) { log.info("valueUnBound:" + event.getName() + " session:" + event.getSession().getId() ); // add you unlock pre here: clearLocksForSession( event.getSession().getId() ); }}


