1. 程式人生 > >java idea如何線上debug

java idea如何線上debug

 

 

 

1 建立一個remote 專案

2 ip 填入遠端的機器

 

3 埠進行檢視 ,catalina.sh

 

4 選擇自己的模組;

 

下面表示成功

 

 

 

引數解釋

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8787

 

dt_socket:使用的通訊方式

server:是主動連線偵錯程式還是作為伺服器等待偵錯程式連線

suspend:是否在啟動JVM時就暫停,並等待偵錯程式連線

address:地址和埠,地址可以省略,兩者用冒號分隔

 

偵錯程式

 

Before Java 5.0, use -Xdebug and -Xrunjdwp arguments. These options will still work in later versions, but but it will run in interpreted mode instead of JIT, which will be slower.

From Java 5.0, it is better to use the -agentlib:jdwp single option:

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044

Options on -Xrunjdwp or agentlib:jdwp arguments are :

  • transport=dt_socket : means the way used to connect to JVM (socket is a good choice, it can be used to debug a distant computer)

  • address=8000 : TCP/IP port exposed, to connect from the debugger,

  • suspend=y : if 'y', tell the JVM to wait until debugger is attached to begin execution, otherwise (if 'n'), starts execution right away.

該答案解釋了,使用-Xdebug方式,主要是在互動模式下適用,它在效能上會弱於使用-agentlib方式。

同時,該答案還解釋了相應的三個引數:

transport:有兩種形式,分別是socket和shared memory,需要跨機器,只能用socket

address:埠號,這裡採用的是tcp協議。我們可以使用

cat /etc/services | grep '8000'

來檢視該埠是否開啟

suspend:如果是y,則需要等B機器上的debugger開啟後,程式才會開始執行。否則,程式啟動時候不會掛起,直接執行。

 

 

java -Xrunjdwp:transport=dt_socket,server=y,address=8000 myApp

This command:

    •  Listens for a socket connection on port 8000.

    •  Suspends this VM before main class loads (suspend=y by default).

    •  Once the debugger application connects, it can send a JDWP command to resume the VM.