6

We have a Java process which we run as a Windows service (using srvany). It runs with Java 1.6 (1.6.0.23 at the moment).

In the past (Windows XP), I could connect JConsole to the processes, on Windows 7 I cannot do this anymore.

If I run jconsole <pid> I get “Invalid process id:4488”. The services are running as SYSTEM user.

If I make the service run as my desktop user (using “Log On as This Account”) the services process ID appear in JConsole, but they are grayed out and I cannot connect.

Is it impossible to dynamically connect to Java processes when they are running as a Windows 7 service?

dakab
  • 5,379
  • 9
  • 43
  • 67
Neil Wightman
  • 1,103
  • 2
  • 9
  • 29
  • Is your JAVA service is configurable to JMX? – Nikunj Jan 12 '11 at 13:30
  • I dont specific anything extra to get JMX enabled, by default (with 1.6 and confirmed when ran at the command line) it works and it worked with Windows XP. – Neil Wightman Jan 12 '11 at 13:35
  • Ok, If JMX is enables then connect the service with JMX URL and port. It should connect. – Nikunj Jan 12 '11 at 13:40
  • Thats the problem. I normally connect simply by the PID not the Port number. – Neil Wightman Jan 12 '11 at 13:53
  • The documentation says "Note - On Windows platforms, for security reasons, local monitoring and management is only supported if your default temporary directory is on a file system that allows the setting of permissions on files and directories (for example, on a New Technology File System (NTFS) file system). It is not supported on a File Allocation Table (FAT) file system, which provides insufficient access controls." So maybe this is the difference between the process running on the command line (or as Windows XP service) and Windows 7 service. – Neil Wightman Jan 12 '11 at 14:14
  • http://stackoverflow.com/questions/503057/unable-to-use-jconsole-with-tomcat-running-as-windows-service – Edd Nov 14 '14 at 09:55

6 Answers6

3

Perhaps it is a 64bit/32bit problem, I have several applications compiled with 32bit JDK, which could not be opened with JConsole from 64bit JDK on Windows 7 64bit, after I downloaded the 32bit JDK it worked.

xu huanze
  • 269
  • 2
  • 9
1

Add the following to JAVA_OPTION

-Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.port=8086 
-Dcom.sun.management.jmxremote.ssl=false 
-Dcom.sun.management.jmxremote.authenticate=false

Then, Use JConsole to connecet remote session: localhost:8086

Ben Cheng
  • 769
  • 10
  • 25
  • Worked for me. Not sure why these params are still required for java 8 even though oracle clearly says it dynamically attach jconsole to java process from java 6 onwards. – Manish Bansal Feb 27 '21 at 09:53
1

Others have been able to run jstack on 2008r2 which may provide some insight on how to get jconsole to connect on Windows 7. As you noted in your comment, the permissions are important. If the service and jconsole can't access the temp directory to write to the appropriate hsperf subdirectory, it won't work. What is also important is the location of the temp directory, the user the service is running, and the user that is running jconsole.

Running SysInternals psexec -s -i <jdk_home>\bin\jconsole <PID> can be used to run jconsole as Local System, the same user that I believe you are using to run your service.

My experience running jconsole from JDK 1.5 in Server 2008 as a system user was unsuccessful. With permissions that I thought should have been sufficient, I got a Could Not Open PerfMemory error. Java 1.6 may be a different story.

In light of all the challenges with running jconsole locally, you would probably have better luck setting it up to accept remote connections. You could set it up for local-only access with your firewall blocking that port from external access.

Community
  • 1
  • 1
Rob Tanzola
  • 1,785
  • 14
  • 11
  • I have tried this and many more tests. Running jconsole as admin, system and changing the service to run as my user etc and it always fails. It appears the hsperfdata_username are created correctly in all cases. – Neil Wightman Mar 15 '11 at 08:42
  • Today I got PsExec.exe -s "C:\Program Files\Java\jdk1.6.0_13\bin\jstack.exe" 12345 and jmap.exe both to work but not jvisualvm. – Neil Wightman Jun 25 '15 at 12:16
0

Change Environment Variable TEMP and Tmp to a different folder that you created. Like c:\theTemp

0

I am currently facing the same problem but on Windows 2003 R2 (SP2). There is on open bug in Oracle Bug database (bug id 6399729) http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6399729

Also there is a work-around posted towards the end. It talks about installing java in "install" mode :-), but didn't work for me on Windows 2003 though. But your mileage may vary!!

Ramesh N
  • 138
  • 6
  • The bug appears to be specific to using jconsole via remote desktop. – Neil Wightman Mar 14 '11 at 15:21
  • Linking a related answer for using /console using Mac OS X RDP tool. This finally works for me. http://serverfault.com/questions/114548/mstsc-admin-for-microsofts-rdp-for-mac-os-x – Ramesh N Nov 30 '12 at 15:17
  • Sometimes jvisualvm fails to run in the above environment. Work around mentioned here seems to work http://stackoverflow.com/questions/8912831/how-do-you-run-jvisualvm-exe-under-the-local-system-account-under-windows-server?rq=1 – Ramesh N Jul 07 '13 at 07:35
0

It might be a problem with the folder %TMP%/hsperfdata_{USER_NAME}. In my case, it worked after I :

  • close all applications running over the JVM
  • delete the folder %TMP%/hsperfdata_{USER_NAME} (exemple: C:/Temp/hsperfdata_MyUser)
  • reopen JConsole (it recreates the folder)

Hope it helps. You can also take a look at this thread in Oracle community.

Gustavo Passini
  • 2,348
  • 19
  • 25