Undeploy may be called several times, but only the call that decreases factoryCount to 0 disconnects the session and removes it from the session manager. This method and predeploy - the only methods altering factoryCount - should be synchronized. After undeploy call that turns factoryCount to 0: session==null; PREDEPLOYED, DEPLOYED and DEPLOYED_FAILED states change to UNDEPLOYED state.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.