Jconsole cannot connect to java processes running as Windows 7 Services
Asked Answered
T

7

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?

Tertias answered 12/1, 2011 at 13:16 Comment(6)
Is your JAVA service is configurable to JMX?Misshape
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.Tertias
Ok, If JMX is enables then connect the service with JMX URL and port. It should connect.Misshape
Thats the problem. I normally connect simply by the PID not the Port number.Tertias
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.Tertias
#503557Shelter
A
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.

Aracelyaraceous answered 5/8, 2011 at 5:8 Comment(3)
I only have 32 bit Java on my systems. We are yet to need 64 bit. I may try it with a 64 bit Java.Tertias
@Mongo was your java process running as a Windows service?Tertias
@NeilWightman no, sorry, this question popped up from a related search and the answer happened to help me. My jvm arch was different between jconsole and my process, but I was not running it as a Windows service.Hoy
C
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.

Cigarette answered 21/1, 2011 at 4:6 Comment(2)
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.Tertias
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.Tertias
F
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

Fecundity answered 30/11, 2015 at 8:12 Comment(1)
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.Olsen
O
1

Good news for others who may hit this, still in 2023: it may be as simple as needing to run the command prompt "as admin" before running jconsole <pid>.

I found I got this error ("Invalid process id", in the popup screen of jconsole) when trying to connect to a jvm which (like Neil) was running as a service (and which had it "logon as" value set to "local system"). Simply opening the cmd prompt as admin let jconsole (and other JVM tools) work fine.

FWIW, note that if you don't use the pid argument, you won't see the process in the "local process" connection tab (even though you can connect to it if you provide it). Of course, if you enable JXM args in the jvm, then you can access it using the "remote process" tab.

I appreciate that this is a very old question and things may have been different when Neil first wrote this in 2011. But I offer it in case it helps anyone else who may find the question here. I've confirmed it with Java 8, 11, and 17.

Olwena answered 7/10, 2023 at 2:1 Comment(0)
M
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) https://bugs.java.com/bugdatabase/view_bug?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!!

Masteratarms answered 1/3, 2011 at 16:36 Comment(3)
The bug appears to be specific to using jconsole via remote desktop.Tertias
Linking a related answer for using /console using Mac OS X RDP tool. This finally works for me. serverfault.com/questions/114548/…Masteratarms
Sometimes jvisualvm fails to run in the above environment. Work around mentioned here seems to work #8913331Masteratarms
R
0

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

Retrograde answered 24/2, 2017 at 15:41 Comment(0)
V
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.

Viridis answered 11/6, 2019 at 15:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.