How To Get Java System Properties and JVM Flags of A Running Java Process - Using Jinfo
How To Get Java System Properties and JVM Flags of A Running Java Process - Using Jinfo
How to get Java system properties and JVM flags of a running Java process - Using jinfo
I wanted to check the current sy stem properties and JV M flags of a Weblogic managed serv er, so I first used "wlst " (Weblogic scripting tool) to access that managed serv er. It was a little time consuming task and y ou need to hav e a knowledge about the inside of Weblogic serv er. But later I found out about this jinfo tool. jinfo is a v ery useful tool for retriev ing Jav a sy stem properties and JV M flags (JV M command line flags) (and changing v alues of JV M flags) of a running local Jav a process or a remote serv er process. It was lot easier than accessing these properties using "wlst " or "jconsole ". According to the "jinfo " documentation, This tool can also be used to get sy stem properties and JV M flags of a remote serv er process. But I am going to focus only about how to get those details of a local Jav a process in a Linux env ironment. Y ou can get the process ID of the specific process by doing a command like below in Linux . (Please replace "managed1 " with a word (main class name, for ex ample) in the command used for starting the Jav a process.)
In the output of abov e command, y ou can get the PID of the relev ant Jav a process. Then ex ecute the following command. Please replace <PID> with the actual PID of the process.(I am assuming that path to JDK bin folder is in PATH env ironment v ariable).
j i n f o< P I D >
It will attach to the process related to that PID and will show the Jav a sy stem properties and JV M flags like below.
A t t a c h i n gt op r o c e s sI D2 5 9 6 5 ,p l e a s ew a i t . . . D e b u g g e ra t t a c h e ds u c c e s s f u l l y . S e r v e rc o m p i l e rd e t e c t e d . J V Mv e r s i o ni s1 1 . 0 b 1 7 J a v aS y s t e mP r o p e r t i e s :
D w e b l o g i c . N a m e = m a n a g e d 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Other features of this tool : (I didn't hav e a chance to ex periment with these y et): 1 . Get only JV M flags of the relev ant Jav a process. jinfo -flags <PID> 2. Get only Jav a sy stem properties jinfo -sy sprops <PID> 3. Get a v alue of a specific JV M flag of the relev ant Jav a process. jinfo -flag <JV M_FLAG_NAME> <PID> 4. Change the v alue of a specific JV M flag of the relev ant Jav a process. a) Enabling a boolean JV M flag, jinfo -flag +<JV M_FLAG_NAME> <PID> b) Disabling a boolean JV M flag, jinfo -flag -<JV M_FLAG_NAME> <PID> c) Setting a v alue of a JV M flag jinfo -flag <JV M_FLAG_NAME>= <NEW_V ALUE> <PID>
If you get VMVersionMism atchException, Sometimes y ou may get following V MV ersionMismatchEx ception.
A t t a c h i n gt op r o c e s sI D6 4 6 1 ,p l e a s ew a i t . . . E x c e p t i o ni nt h r e a d" m a i n "j a v a . l a n g . r e f l e c t . I n v o c a t i o n T a r g e t E x c e p t i o n a ts u n . r e f l e c t . N a t i v e M e t h o d A c c e s s o r I m p l . i n v o k e 0 ( N a t i v eM e t h o d ) a ts u n . r e f l e c t . N a t i v e M e t h o d A c c e s s o r I m p l . i n v o k e ( N a t i v e M e t h o d A c c e s s o r I m p l . j a v a : 3 9 ) a ts u n . r e f l e c t . D e l e g a t i n g M e t h o d A c c e s s o r I m p l .
The reason for this is, y ou are using a "jinfo " tool related to a different jav a v ersion than the JV M used to start this targeted process. If y ou get abov e ex ception, please find the JDK home of the JV M used for the targeted process, and use the "jinfo " tool in the bin folder of that JDK home. According to the jinfo tool documentation, it seems this is not a standard tool of the JDK. In the documentation, there is a note say ing "NOT E - T his utility is unsupported and m ay or m ay not be av ailable in future v ersions of the JDK. In Windows Sy stem s where d b g e n t . d l lis not present, 'Debugging T ools for Windows' needs to be installed to hav e these tools working. Also the P A T Henv ironm ent v ariable should contain the location of j v m . d l lused by the target process or the location from which the Crash Dum p file was produced. For ex am ple, s e tP A T H = \ j r e \ b i n \ c l i e n t ; % P A T H %
"