DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Apache Cassandra Horizontal Scalability for Java Applications [Book]
  • Prometheus and Grafana Integration With Java Applications
  • What Do We Know About Tomcat 9.0
  • Dust Actors and Large Language Models: An Application

Trending

  • Integrating Security as Code: A Necessity for DevSecOps
  • Medallion Architecture: Why You Need It and How To Implement It With ClickHouse
  • Event-Driven Architectures: Designing Scalable and Resilient Cloud Solutions
  • Unlocking the Potential of Apache Iceberg: A Comprehensive Analysis
  1. DZone
  2. Data Engineering
  3. Databases
  4. Redis-Based Tomcat Session Management

Redis-Based Tomcat Session Management

Learn what Tomcat clustering is and what problems it can solve by working together with Redis.

By 
Nikita Koksharov user avatar
Nikita Koksharov
·
Updated Aug. 23, 21 · Tutorial
Likes (20)
Comment
Save
Tweet
Share
58.2K Views

Join the DZone community and get the full member experience.

Join For Free

Apache Tomcat clustering can seem a bit overwhelming to someone who doesn't fully understand it, but, actually, it's not that complex. Clustering can be defined as using a combination of load balancing, some form of session replication, and multiple server "workers" to process the balanced load.

What Problems Are Solved by Tomcat Clustering?

Some of the problems that Tomcat clustering is used to solve include the following. First, when a server is receiving too many incoming requests such that it cannot handle them efficiently. Second, when a stateful application requires, in case the server fails, a way to preserve session data. Third, a developer wants a way to change the configuration or to update their applications without interrupting service. These are the main reasons that we need to use Tomcat Cluster. But is there a proper way to use Tomcat Cluster that is particularly good?

What Is Redis?

Redis is an in-memory open-source data project. In fact, it is the most popular in-memory database that is currently available. In particular, Redisson can be used as a Redis Java client. Redisson uses Redis to empower Java applications for companies' use. It is intended to make your job easier and develop distributed Java applications more efficiently. Redisson offers distributed Java objects and services backed by Redis.

How Can Redis Be Used for Tomcat?

Redisson's Tomcat Session Manager allows you to store sessions of Apache Tomcat in Redis. It empowers you to distribute requests across a cluster of Tomcat servers. This is all done in non-sticky session management backed by Redis.

Alternative options might serialize the whole session. However, with this particular Redis Tomcat Manager, each session attribute is written into Redis during each invocation. Thanks to this advantage, Redisson Session Manager beats out other Redis-based managers in storage efficiency and optimized writes. Tomcat Session Management, in this way, is used in the most ideal way possible.

Step 1

Add RedissonSessionManager into tomcat/conf/context.xml

<Manager className="org.redisson.tomcat.RedissonSessionManager"
          configPath="${catalina.base}/redisson.conf" readMode="MEMORY" updateMode="DEFAULT"/>


readMode - read attributes mode. Two modes are available:

  • MEMORY - stores attributes in local Tomcat Session and Redis. Further Session updates propagated to local Tomcat Session using Redis-based events. Default mode.
  • REDIS - stores attributes into Redis only.

updateMode - attributes update mode. Two modes are available:

  • DEFAULT - session attributes are stored into Redis only through setAttribute method. Default mode.
  • AFTER_REQUEST - all session attributes are stored in Redis after each request.

Step 2

Copy two jars into TOMCAT_BASE/lib directory

  • redisson-all-3.10.6.jar

    • for Tomcat 6.x: redisson-tomcat-6-3.10.6.jar

    • for Tomcat 7.x: redisson-tomcat-7-3.10.6.jar

    • for Tomcat 8.x: redisson-tomcat-8-3.10.6.jar

    • for Tomcat 9.x: redisson-tomcat-9-3.10.6.jar

The reason for using Redis Tomcat Manager to do Tomcat Clusters is if you are expecting a lot of web traffic, i.e. if your site will be expanding, or if you just want a little more help to take on the load in order to increase your availability.

What Else Can Redisson Do?

Redis-based Tomcat Session Management is not the only thing Redisson can provide. Once you are done with your cluster project, check it out for its other benefits. Redisson can provide distributed Java applications. It offers different caching implementations like JCache API, Hibernate 2nd Level Cache, and Spring Cache. It supports read/write caching for databases, distributed implementations of ExecutorService and ScheduledExecutorService, and a Java-based MapReduce programming to support "large amounts of data" that is stored in Redis.

Overall, Redisson can do a lot. Tomcat Session Management can seem overwhelming but can be easily resolved with Redisson. Plus, you may find a lot of other features that meet your needs along the way.

Apache Tomcat Session (web analytics) Redis (company) clustering Database application Attribute (computing) Open source Java (programming language) In-memory database hadoop

Opinions expressed by DZone contributors are their own.

Related

  • Apache Cassandra Horizontal Scalability for Java Applications [Book]
  • Prometheus and Grafana Integration With Java Applications
  • What Do We Know About Tomcat 9.0
  • Dust Actors and Large Language Models: An Application

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!