Skip Headers

Oracle TopLink Developer's Guide 10g Release 3 (10.1.3) B13593-01 |
| Home | Solution Area | Contents | Index

Previous | Next |

# Destroying Sessions in the Session Manager Instance

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 78-14 illustrates. If the specified session is not in the session manager cache, a `ValidationException` is thrown.

Example 78-14 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 78-15 illustrates.

Example 78-15 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();