Tomcat, out of memory under gentoo

Sometimes, you just need to give tomcat more than its 64megs that comes out of the box.

There’s the nice way to do it under gentoo:

edit /etc/env.d/21tomcat – it should already be there.

Add the following line to it:

CATALINA_OPTS="-server -Xms128M -Xmx256M"

This means you’re telling catalina (the tomcat engine) to start with an initial heap size of 128 megs. It also tells it to set its maximal heap size to 256 megs.

/etc/env.d is Gentoo’s way of nicely handling global environment variables. But its not all magic. You need to let gentoo know you’ve made changes.

Run the following command:


This will regenerate the environment variables. This is neat. But the shell you’re currently running doesn’t know that. You could log off and log back on, but I’ve got better.

source /etc/profile

Now, if you run echo $CATALINA_OPTS you’ll see the CATALINA_OPTS variable is set to what you put in the environment file.

This is all neat, but tomcat needs to be aware of this as well… so you’ll need to restart it.

/etc/init.d/tomcat5 restart

Enjoy your enhanced heap size!

UPDATE 2009/03/27 For people stumbling onto this article – the way to go now is to edit the tomcat configuration file in /etc/conf.d instead.