1. 程式人生 > >java 的hsperfdata_%USERNAME%資料夾不能自動生成原因解決

java 的hsperfdata_%USERNAME%資料夾不能自動生成原因解決

現象

使用jps不能檢視java 的程序,使用visualVm不能監控到本地的java程式,並且提示"Local Applications Cannot Be Detected (Error Dialog On Startup)".

原因分析

java程式啟動後,預設會在 %TEMP%/hsperfdata_%USERNAME% 目錄下以該程序的id為檔名新建檔案,並在該檔案中儲存jvm執行的相關資訊,其中%TEMP%為wiondows系統的臨時目錄(在檔案地址中輸入"%TEMP%"即可跳轉到此目錄下);%USERNAME% 為當前的使用者名稱(可通過cmd中輸入echo %USERNAME% 檢視

).%TEMP%/hsperfdata_%USERNAME% 目錄會存放該使用者所有已經啟動的java程序資訊。

而jps、jconsole、jvisualvm等工具的資料來源就是這個檔案(/%TEMP%/hsperfdata_%USERNAME%/pid)。所以當該檔案不存在或是無法讀取時就會出現jps無法檢視該程序號.

解決

Local Applications Cannot Be Detected (Error Dialog On Startup)

Description: An error dialog saying that local applications cannot be detected is shown immediately after VisualVM startup.
Resolution: This can happen on Windows systems, it's caused by misconfigured jvmstat technology used to detect the running applications. There are two possible causes:
Insufficient permissions for %TMP%\hsperfdata_username folder - make sure you're able to create a file in the directory and eventually update the permissions for full folder access. Alternatively you can just re-create the folder which should automatically set the correct access rights. See see this forums.sun.com thread for more details.

Having %TMP%\hsperfdata_username folder on a FAT disk - by default jvmstat doesn't work on FAT disks due to security restrictions. You can bypass the security check by setting the -XX:+PerfBypassFileSystemCheck flag for both VisualVM and the monitored application. See the JDK bug #5042659 for more details.(訪問地址:

點選開啟連結)

--- https://visualvm.java.net/troubleshooting.html#jpswin