简体   繁体   中英

How to do a thread dump on Azure App Service?

I have an Azure App Service running Tomcat 8.5 and can't seem to figure out how to do a thread dump. jstack is not recognized in the Console nor the DebugConsole.

On Azure App Service, all popular versions of Java had been installed at the path D:\\Program Files (x86)\\Java . Take version 1.8.0u73 as example, please see the figure below.

在此处输入图片说明

You can command set PATH=D:\\Program Files (x86)\\Java\\jdk1.8.0_73\\bin;%PATH% to add Java tools to the environment temporarily via the Kudu console tool. Then, the jstack tool is available in the current Kudu session.

Inspired by the previous answer, I created the following bat script (could be powershell, I suppose) that does the job:

powershell -Command "get-process java |select -expand id" > pid.txt
set /p id= < pid.txt
"%JAVA_HOME%\bin\jstack" -F %id% > out.txt

It uses the java version that you're using in your app (JAVA_HOME) and doesn't require any input from you. It's simple and does the trick. Just create a bat file in your wwwroot, for example, and run it whenever you want.

I know this is an old question but for Windows Apps on Azure App Service, this can be easily done by going to Azure Portal -> Diagnose and Solve problems blade -> Diagnostic Tools and then choosing Collect Java Thread dump from the left menu or the middle pane.

截图诊断和解决刀片

  • Get the PID of java process from Process Explorer of Kudu (Advanced Tools)
  • Use this command to collect thread dump: jcmd Thread.print > D:\home\threaddump.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM