Monday, July 6, 2009

A neat way to monitor windows services

The JDK supplies a very impressive toolchest which enables you to monitor the JVM(
jconsole, jps, jmap,jvisualvm etc...). There are also other tools such as BTrace which can attach to the JVM and solve performance problems.
On UNIX you only need to use su or sudo and act as the user running the JVM. Doing that you can attach to it and apply all commands.
In Microsoft Windows the situation is more complicated. The service processes run under a different user and in another session and you are not able to connect to them.

But do not panic:-) I am suggesting here a simple workaround.

Step 1:
Download and install the Resource Kit Tools from Microsoft. (The 2003 version will also run on Windows XP). Didn't try Vista/2008 but then again who uses Vista.

Step 2:
Run the following command:
%RESKIT_HOME%\Tools\Instsrv.exe" SrvCMD "%RESKIT_HOME%\Tools\Srvany.exe"
It will create a service named SrvCMD (in case you have such a service use a different name)

Step 3:
Open services.msc and update the service properties to run manually. Check "allow service interact with desktop" box.

Step4:
Execute regedit.
Open the key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SrvCMD
Add a sub-key named Parameters
To this sub-key add a string value named Application. Its value will be the name of the executable you want to run. In our case c:\WINDOWS\system32\cmd.exe.

Step5:
Note: If you are connecting with remote desktop make sure you are connecting with /console parameter (otherwise you will not see the command window)
Start the service.
A window with command prompt running in the session of the service will be opened.
jps will now discover your JVM.


Enjoy!

Friday, July 3, 2009

BTrace session slides

BTrace session is over.
I worked very hard preparing it though I think I needed more time for working on the running examples and integrating them seamlessly with the presentation.
It was a fascinating experience for me.It is the first time for me that I am arranging a public session and I am sure that more will come.
37 Attendees(out of max 50 available seats) two and a half hours of covering BTrace.
The responses were very positive. People were very enthusiastic about the tool.
I have published the slides of two presentations from the event in my web site:
The participants of the event are entitled to participate in a lottery upon submitting a final exercise!