Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have set up a Tomcat server using Server 2008 and IIS 7.
How can I tell if the JAVA_OPTS environment variable is actually being used?

I've heard before that the I have to edit the service.bat file in order to make the JAVA_OPTS environment variable be used, but how can I tell if it's successful?

I haven't been able to find out if there is a way to view this in the logs or something else more quantitative. The only way I could think of to try to test it is to edit the variable and try to tell if there is a difference in performance. I set the JAVA_OPTS to be the following:

-server -Xmx1k -Xms1k-Xmn1k -Xss128k -XX:+UseParallelGC -XX:ParallelGCThreads=20 -XX:PermSize=1k -XX:MaxPermSize=1k  

Also, I found documentation saying to change the following line in service.bat from:

"%EXECUTABLE%" //US//%SERVICE_NAME% ++JvmOptions "-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties" --JvmMs 128 --JvmMx 256

to:

"%EXECUTABLE%" //US//%SERVICE_NAME% ++JvmOptions "-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties" %JAVA_OPTS%

I got no errors when I ran the command

service install ServiceName

So far everything seems to be running as fast as it always is before I reinstalled the service with the changed memory settings, making me think that the JAVA_OPTS isn't affecting anything.

Sorry if this is a broad sort of question, but I haven't found a good lead to go off of yet as to what is actually happening in the back end. Can somebody shed some light on this?

share|improve this question
1  
Instead of futzing with .bat files you should be using the Tomcat7w.exe utility to modify the service settings. –  EJP Jul 26 '12 at 7:03

2 Answers 2

You can use the jinfo utility that comes with the JDK to query the VM flags and system properties at runtime.

share|improve this answer
    
Okay, this does seem to be what I'm looking for, however I can't get it to work. I ran the following command in my batch file: %JAVA_HOME%\bin\jinfo -flag ParallelGCThreads %tomcat_pid% and I get the following message returned: Not enough storage is available to process this command –  OrangeGrover Jul 31 '12 at 21:12
    
This error is most often seen when running Tomcat as a Windows service . Tools like jinfo can't reach the service because of security restrictions. One option is to run Tomcat from the command line. If you want to keep it running as a service, there are ways to do it, but they involve a bit a work. For example: stackoverflow.com/questions/906620/… –  David Levesque Aug 1 '12 at 1:05
    
Cool, thanks for the lead. –  OrangeGrover Aug 3 '12 at 15:14
up vote 0 down vote accepted

Alright, I found the information I was looking for so I'm going to accept my answer because I'm giving more details, but +1 to David Levesque for the leads.

I found out that the memory settings I was trying to set were not being used. In order to change the memory settings I used the tomcat7w in the \bin folder.

Run the following command:

tomcat7w //ES//<ServiceName>

Then the following should pop up:

Java Service Manager

Click the Java tab that is underlined and add the arguments in the highlighted areas.


In order to check this, I used the jinfo executable (in the \bin folder). Jinfo prints Java configuration information for a given Java process. Run this command using the following syntax:

jinfo -flags PID-of-Tomcat-executable

The following little script saved me some time from having to find out Tomcat's PID every time, so I figured I may as well post it here:

@echo off
for /f "tokens=1,2 delims= " %%i in ('=tasklist ^| findstr "tomcat"') do (
    echo Tomcat Executable = %%i
    echo Tomcat Process ID = %%j
    set tomcat_pid=%%j
)
echo %tomcat_pid%
%JAVA_HOME%\bin\jinfo -flags %tomcat_pid%
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.