Line Cheng: Name your thread, look at your system

Source: Internet
Author: User
Tags thread

The development Environment (IDE) provides a good debugging tool for graphical interface applications, but it cannot debug a multithreaded Java server program.

Fortunately, there are several tools, such as the Logging Application Interface (API) or Java debugger, that can be used to debug Java server programs. Developers can also use a system's line Cheng to observe the state of the system at any time.

Running the server and then pressing [CTRL] [/] will run a system line Cheng, which will output all currently running threads, for example:

^\full Thread Dump:

Thread-1 "prio=5 tid=0x87fe0 nid=0x800013b8 waiting on Monitor [0..0XBFFFE9F8]

"Thread-0" prio=5 tid=0xafde0 nid=0x72a00 runnable [0x173f000. 0X173FB48]

At Java.net.PlainSocketImpl.socketAccept (Native method)

At Java.net.PlainSocketImpl.accept (plainsocketimpl.java:421)

At Java.net.ServerSocket.implAccept (serversocket.java:243)

At Java.net.ServerSocket.accept (serversocket.java:222)

At Com.generationjava.net.PortListener.run (portlistener.java:38)

At Java.lang.Thread.run (thread.java:496)

"Signal Dispatcher" daemon prio=10 tid=0xa5f80 nid=0x52af0 waiting on Monitor [0..0]

"Finalizer" daemon prio=8 tid=0xa46c0 nid=0x4d930 waiting on Monitor [0x10a8000. 0X10A8B48]

At Java.lang.Object.wait (Native method)

At Java.lang.ref.ReferenceQueue.remove (referencequeue.java:108)

At Java.lang.ref.ReferenceQueue.remove (referencequeue.java:123)

At Java.lang.ref.finalizer$finalizerthread.run (finalizer.java:162)

"Reference Handler" daemon prio=10 tid=0xa3b70 nid=0x4cca0 on Monitor [waiting. 0X1027B48]

At Java.lang.Object.wait (Native method)

At Java.lang.Object.wait (object.java:420)

At Java.lang.ref.reference$referencehandler.run (reference.java:110)

"VM Thread" prio=5 tid=0xa2de0 nid=0x4ca20 runnable

"VM periodic Task Thread" prio=10 tid=0xa56b0 nid=0x52890 waiting on Monitor

The following four threads are standard threads, while others relate to running server programs. These two threads are named Thread-1 and Thread-0, and if thread th = new Thread (runnable, "Server") is substituted for thread th = new Thread (runnable) to create the process, You can name the thread you want to create.

In addition, if you call the Java.lang.Thread SetName (String) method, you can also name your thread, and it is easy to find out from the output of the line Cheng that the original Thread-0 is a server program.

"Server" prio=5 tid=0xafde0 nid=0x72a00 runnable [0x173f000 ... 0X173FB48]

And the original Thread-1 thread now becomes Thread-0.

By naming threads and getting line Cheng, developers can see the internal state of the Java Virtual Machine (JVM). If you want more information, you have to study the Java debugger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.