Skip Headers

# Destroying Sessions in the Session Manager Instance

Previous

Next

You can destroy sessions individually by name or destroy all sessions.

Note: You should only do this when a J2EE application is un-deployed, or when the entire application is shut down and only when it is known that the session is no longer in use. You should log out of a session before destroying it (see "Logging Out of a Session"). If you do not log out of a session, the session manager will at the time you use it to destroy a session.

To destroy one session instance by name, use `SessionManager` method `destroySession`, as Example: Destroying a Session in the Session Manager illustrates. If the specified session is not in the session manager cache, a `ValidationException` is thrown.

Destroying a Session in the Session Manager

    SessionManager manager = SessionManager.getManager();
    Server server = (Server) manager.getSession("myserversession");
    …
    // Destroy session by name. If the session named myserversession is not in the
    // session manager cache, throw a ValidationException
    manager.destroySession("myserversession");

To destroy all session instances, use the `SessionManager` method `destoryAllSessions`, as Example: Destroying All Sessions in the Session Manager illustrates.

Destroying All Sessions in the Session Manager

    SessionManager manager = SessionManager.getManager();
    Server server = (Server) manager.getSession("myserversession");
    SessionBroker broker = (SessionBroker) manager.getSession("mysessionbroker");
    …
    // Destroy all sessions stored in the session manager
    manager.destroyAllSessions();