WebLogic 輸出 BEA-000337 警告提示 Stuck Thread(超過 StuckThreadMaxTime 默認 600 秒),僅作提示不干預。若因死鎖導致線程永久卡住,往往只能重啟。利用 JVMTI/JDI 可精準中斷特定 Stuck Thread,避免重啟業務中斷。
"[ACTIVE] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)'"。-Xdebug -Xrunjdwp:transport=dt_socket,address=9191,server=y,suspend=n。Bootstrap.virtualMachineManager().attachingConnectors() 獲取 SocketAttachingConnector,連接 localhost:9191。public void terminateThread(String threadNamePattern) {
List<ThreadReference> threads = vm.allThreads();
for (ThreadReference tr : threads) {
if (tr.name().contains(threadNamePattern)) {
tr.interrupt(); // 發送 InterruptedException
System.out.println("Terminated: " + tr.name());
return;
}
}
System.out.println("No matched thread found.");
}
測試線程執行 Thread.sleep(),調用上述方法後,目標線程拋出 InterruptedException: sleep interrupted,堆疊清晰可見,業務邏輯可在 catch 塊中釋放資源、記錄日誌、優雅退出。
interrupt() 僅發送中斷信號,無法強制終止原生代碼或忽略中斷的代碼路徑(如無限循環無阻塞調用)。結合 ThreadMXBean 定期掃描長時間運行線程,自動產生 Thread Dump 並推送至運維平台,實現「檢測-診斷-干預」閉環,最大程度降低重啟頻率。