"How Tomcat work" Porter Chapter 9:session Management

Source: Internet
Author: User

The Catalina version of Tomcat provides session management through the Manager palette, which is usually associated with the context where a manager instance is in the context class.

Session interface

 Public InterfaceSession { Public Static FinalString session_created_event = "CreateSession";  Public Static FinalString session_destroyed_event = "Destroysession";  PublicString Getauthtype ();  Public voidSetauthtype (String authtype);  Public LongGetCreationTime ();  Public voidSetcreationtime (LongTime );  PublicString getId ();  Public voidsetId (String ID);  PublicString getInfo ();  Public LongGetlastaccessedtime ();  PublicManager GetManager ();  Public voidSetmanager (manager manager);  Public intGetmaxinactiveinterval ();  Public voidSetmaxinactiveinterval (intinterval);  Public voidSetnew (Booleanisnew);  PublicPrincipal Getprincipal ();  Public voidSetprincipal (Principal Principal);  PublicHttpSession getsession ();  Public voidSetvalid (BooleanisValid);  Public BooleanIsValid ();  Public voidaccess ();  Public voidAddsessionlistener (Sessionlistener listener);  Public voidexpire ();  PublicObject getnote (String name);  PublicIterator getnotenames ();  Public voidrecycle ();  Public voidremovenote (String name);  Public voidRemovesessionlistener (Sessionlistener listener);  Public voidsetnote (String name, Object value);}

The commonly used httpsession is to inherit the session interface. Instances of the session are managed in the manager.

First, Manager

The most basic function of manager is to save the session, use HashMap to save, delete,

Manager interface

 Public InterfaceManager { PublicContainer GetContainer ();  Public voidSetcontainer (Container Container);  PublicDefaultcontext Getdefaultcontext ();  Public voidSetdefaultcontext (Defaultcontext defaultcontext);  Public Booleangetdistributable ();  Public voidSetdistributable (Booleandistributable);  PublicString getInfo ();  Public intGetmaxinactiveinterval ();  Public voidSetmaxinactiveinterval (intinterval);  Public voidAdd (session session);  Public voidAddpropertychangelistener (PropertyChangeListener listener);  PublicSession createsession ();  PublicSession findsession (String ID)throwsIOException;  Publicsession[] Findsessions ();  Public voidLoad ()throwsClassNotFoundException, IOException;  Public voidRemove (session session);  Public voidRemovepropertychangelistener (PropertyChangeListener listener);  Public voidUnload ()throwsIOException;}

Subdivide various manager

(1) Standardmanager

The most general manager, copy save session in memory. Likewise to inherit, Lifecycle interface convenient to start and end. At stop, the authenticated session is serialized into a file, and the reload is re-read.

Similarly, Standardmanager will destroy the expired session.

The TOMCAT4 will be opened by a dedicated thread. So Standardmanager will inherit and implement the Java.lang.Runnable interface. After a period of time, the session is detected and destroyed by Processexpires ().

In Tomcat5, the

 Public void backgroundprocess () {processexpires ();}

To proceed. This method is called by Standardcontext's Backgroundprocess method,

(2) Persistentmanager

Persistentmanager inherits the Persistentmanagerbaseh interface.

The difference between Persistentmanager and Standardmanager is that Persistentmanager will manage the session through a second tier of storage, such as in files and databases.

This is done through a private class, private store store;

You can also go back up, restore the session when the server is down, and swap out to save memory by removing some inactive session heavy memory.

The TOMCAT4 also opens a thread to complete these functions.

The TOMCAT5 is passed backgroundprocess ();

(3) Distributedmanager

Distributedmanager is a subclass of Persistentmanager, Distributedmanager is the cluster management to solve the session

Applying the manager at Tomcat startup

Manager Manager = new Standardmanager ();

Context.setmanager (manager);

"How Tomcat work" Porter Chapter 9:session Management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.