About Tomcat’s default session manager

Tomcat’s default session manager is “StandardManager”. (org.apache.catalina.session.StandardManager) Without specific setting, StandardManager manages session data.

Class hierarchy

standard_manager

  • All session manager must implement Manager interface. (Cluster manager also implements Manager)

 

How StandardManager works?

Usually, you create session as follows.


public void someMethod(HttpServletRequest request){

HttpSession session = request.getSession();

}

What happens inside this code?

HttpServletRequest.getSession() -> ApplicationHttpRequest.getSession() -> ManagerBase.createSession() -> StandardSession.setId() -> StandManager.add()

Except HttpServletRequest, all classes are Tomcat’s internal classes. Most logic to handle session data is inside ManagerBase which is parent of StandardManager. The folloging is main function of ManagerBase.

  • Session data is managed at ManagerBase.sessions member variable
  • ManagerBase.sessions’s type is ConcurrentHashMap<String, Object>
  • ManagerBase.sessions.put() is called when a session is created. (Key is session id, value is session data)
  • ManagerBase.sessions.get() is called when retrieve the session
  • ManagerBase.sessions.remove() is called when removing the session

 

How does Tomcat decide which Manager to use?

Inside context.xml, <Context> tag can have <Manager> sub tag. (Usually <Manager> is not declared. Therefore default value is applied)

<Manager> tag has “className” attribute whose default value is “org.apache.catalina.session.StandardManager“. By changing this value, you can make custom session manager. (More detailed options )Next time, I’ll explain how to use custom session manager.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.