There's more...

The best way to set up a Java EE cluster today is using containers (specially Docker containers). So, I'd recommend that you have a look at the Chapter 11, Rising to the Cloud – Java EE, Containers, and Cloud Computing chapter. If you mix that content with this, you will have a powerful environment for your application.

To allow your application to share its session with all nodes in the cluster, you need to edit the web.xml file, find the web-app node, and insert this:

<distributable/>

Without it, your session clustering will not work.

Get Java EE 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.