From f8f34858446e8d7cd34aad31ac8f5cd80ba525fc Mon Sep 17 00:00:00 2001 From: Jinbo Wang Date: Tue, 31 May 2022 15:17:57 +0800 Subject: [PATCH] Increase polling frequency to ensure that Java processes are detected (#416) * Increase polling frequency to ensure that Java processes are detected --- .../java/debug/core/adapter/handler/LaunchUtils.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/LaunchUtils.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/LaunchUtils.java index fc89bfa7c..ca7d69a99 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/LaunchUtils.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/LaunchUtils.java @@ -117,7 +117,7 @@ public static ProcessHandle findJavaProcessInTerminalShell(long shellPid, String ProcessHandle shellProcess = ProcessHandle.of(shellPid).orElse(null); if (shellProcess != null) { int retry = 0; - final int INTERVAL = 100; + final int INTERVAL = 20/*ms*/; final int maxRetries = timeout / INTERVAL; final boolean isCygwinShell = isCygwinShell(shellProcess.info().command().orElse(null)); while (retry <= maxRetries) { @@ -127,11 +127,17 @@ public static ProcessHandle findJavaProcessInTerminalShell(long shellPid, String }).findFirst(); if (subProcessHandle.isPresent()) { + if (retry > 0) { + logger.info("Retried " + retry + " times to find Java subProcess."); + } logger.info("shellPid: " + shellPid + ", javaPid: " + subProcessHandle.get().pid()); return subProcessHandle.get(); } else if (isCygwinShell) { long javaPid = findJavaProcessByCygwinPsCommand(shellProcess, javaCommand); if (javaPid > 0) { + if (retry > 0) { + logger.info("Retried " + retry + " times to find Java subProcess."); + } logger.info("[Cygwin Shell] shellPid: " + shellPid + ", javaPid: " + javaPid); return ProcessHandle.of(javaPid).orElse(null); } @@ -147,8 +153,9 @@ public static ProcessHandle findJavaProcessInTerminalShell(long shellPid, String } catch (InterruptedException e) { // do nothing } - logger.info("Retry to find Java subProcess of shell pid " + shellPid); } + + logger.info("Retried " + retry + " times but failed to find Java subProcess of shell pid " + shellPid); } return null;