I'm running tomcat 5.0.24 as a service on windows XP and I need to increase the amount of memory available. It appears that the only way to do this is to edit the registry.
So I opened regedit and navigated to:
HKEY_LOCAL_MACHINE >> SOFTWARE >> Apache Software Foundation >> Procrun 2.0 >> Tomcat5 >> Parameters >> Java
Under the Java element there are seven values:
Name Type Data
----------------------------------------------------------
(Default) REG_SZ (value not set)
Classpath REG_SZ C:\tomcat5\bin\bootstrap.jar
Jvm REG_SZ C:\j2sdk1.4.2_03\jre\bin\server\jvm.dll
JvmMs REG_DWORD 0x00000100 (256)
JvmMx REG_DWORD 0x00000100 (256)
JvmSs REG_DWORD 0x00000100 (256)
Options REG_MULTI_SZ -Dcatalina.home=C:\tomcat5 -Djava.endorsed.dirs=C:\tomcat5\common\endorsed -Djava.io.tmpdir=C:\tomcat5
Now the JvmMx, JvmMx, and JvmSs values were all initiall 0 and I had initially changed them each to decimal 256,000,000 but when I did this tomcat would not start as a service and I found my logs contained the following error:
[2004-06-02 13:02:43] [info] Starting service...
[2004-06-02 13:02:43] [info] JNI Invalid initial heap size: -Xms256000000m
[2004-06-02 13:02:43] [415 javajni.c] [error] CreateJavaVM Failed
[2004-06-02 13:02:43] [770 prunsrv.c] [error] Failed initializing java C:\Tomcat5\bin\bootstrap.jar
[2004-06-02 13:02:43] [982 prunsrv.c] [error] ServiceStart returned 2
This was actually an encouraging error, I thought, since it indicated that I had gone to the correct place to set the heap size. Now all I had to do was provide a reasonable value. So I changed 256,000,000 to 256 (which is the value they are at now and the value I recorded above when copying down the regedit parameters) and tried again.
Tomcat now starts just fine, but when I tested the memory allocations using the following code in the init method of one of my servlets it indicated that the memory settings had not been increased.
Here is the code from the init method.
Runtime rt = Runtime.getRuntime();
System.out.println("Max Memory :" + rt.maxMemory() );
System.out.println("Free Memory :" + rt.freeMemory() );
System.out.println("Total memory:" + rt.totalMemory() );
Here is what it printed:
Max Memory :66650112
Free Memory :11874424
Total memory:59592704
So I have tried to increase the memory available to tomcat and have failed. If someone can tell me what I'm doing wrong I'll be remarkably impressed.