View the JDK thread log

Source: Internet
Author: User
Tags jboss jboss server log4j

Command: Jstack (View Thread), Jmap (view memory), and Jstat (profiling) commands

These commands must perform the EQ under the Linux JDK bin path:

./jstack 10303 If you want to print the content into text, the./jstack 10303 >111.log Print to a 111.log file, and then SZ 111.log is downloaded to the local view.

Jmap-histo pid (view instance)

How to know the current Linux system JDK path, can be PS Aux|grep JDK can see the path, generally/usr/java/jdk1.x.x/y/bin

Below is an introduction:

Jstack (view threads), Jmap (view memory) and Jstat (performance analysis) commands blog categories:
    • Java I/O system
    • Java Basics
An article shared by colleagues inside the company
See an example of using Jstack to view a deadlock on the weekend. Last night summed up the Jstack (view thread), Jmap (view memory), and Jstat (performance analysis) commands. For everyone's reference
1. Jstack 1.1 Jstack can get information on Java stack and native stack running Java programs. It is easy to know how the current thread is running. As shown in note: This and thread dump are the same results. But thread dump is using the kill-3 PID command, or the server is less use Kill for the wonderful
1.2 Named row format jstack [option] PID jstack [option] executable core jstack [option] [email Protected]]remote-hostnam E-or-ip is the most commonly used or jstack PID
1.3 In thread Dump, note the following state deadlocks, Deadlock (focus on) waiting for resources, waiting on condition (focus on) • Wait for the monitor, waiting on monitor entry (focus Note) blocking, Blocked (focus on) • Execution, runnable pause, suspended object waiting, object.wait () or timed_waiting stop, parked below is a detailed example of this Analysis, we refer to the original http://www.cnblogs.com/zhengyun_ustc/archive/2013/01/06/dumpanalysis.html
1.4   in thread dump, there are several threads that are defined as follows   the thread name belongs to the explanatory Note   Attach Listenerjvmattach Listener thread is responsible for receiving external commands, The command is executed and the result is returned to the sender. Usually we use some commands to ask the JVM to give us some feedback, such as Java-version, Jmap, Jstack, and so on. If the thread is not initialized when the JVM is started, it will be started when the user first executes the JVM command.   Signal DISPATCHERJVM Before we mentioned the first attach listener thread is responsible for receiving external JVM commands, and when the command is received successfully, it will be handed to the Signal Dispather thread to distribute to various module processing commands , and returns the processing result. The signal Dispather thread is also initialized when the external JVM command is received for the first time.   COMPILERTHREAD0JVM is used to invoke jiting to compile the loading class in real time. Typically, the JVM initiates multiple threads to handle this part of the work, and the number following the name of the thread is incremented, for example:compilerthread1  Concurrent mark-sweep GC The THREADJVM concurrency token clears the garbage collector (which is usually referred to as the CMS GC) thread, which is primarily intended for garbage collection in the old age. PS: Enable the garbage collector, you need to add:-xx:+useconcmarksweepgc  DESTROYJAVAVMJVM executes main () thread in the JVM startup parameter to invoke the Jni_ in JNI after main execution is complete The DESTROYJAVAVM () method evokes the DESTROYJAVAVM thread.    after the Jboss server is started, the JVM will invoke the DESTROYJAVAVM thread, wait, and notify it to unload the JVM while other threads (Java threads and native threads) exit. When a thread exits, it will determine whether it is currently the last non-deamon thread in the entire JVM, and if so, notifies the DESTROYJAVAVM thread to unload the JVM.   ps:  Extension:  1. If the thread exits with the judgment that it is not the last non-Deamon thread, call Thread->exit (false) and throw the Thread_end event, the JVM does not exit.   2. If the thread exits to judge itself as the last non-Deamon thread, then call the Before_exit () method, throw two events:  event 1:thread_end thread End event, event 2:VM death event.       then call the Thread->exit (True) method, then remove the thread from the active list, delete the thread, and so on after a series of work finishes, notifies the waiting DESTROYJAVAVM The thread performs an unload JVM operation.   Containerbackgroundprocessor Thread JBoss It is a daemon thread that initializes the JBoss server when it is started, and the main task is to check periodically if the session expires. Expired clears .  Reference:http://liudeh-009.iteye.com/blog/1584876 
dispatcher-thread-3  thread log4j      log4j has the ability to print logs asynchronously, appender that require an asynchronous print log need to be registered to Asyncappender object inside, by the Asyncappender to listen, decide when to trigger the log printing operation. Asyncappender If the supervisor hears that appender in its jurisdiction has a print log operation, it generates a corresponding event for the Appender and saves the event in a Buffuer region.   DISPATCHER-THREAD-3 thread is responsible for determining if the event buffer is full, and if it is full, distribute all the event in the buffer to the Appender container. Those registered Appender receive their own event, then start processing their own log printing work. The dispatcher-thread-3 thread is a daemon thread.   Finalizer thread JVM This thread is also created after the main thread, with a priority of 10, primarily used to call the Finalize () method of the object before garbage collection, and a few:  on finalizer threads 1) The Finalize () method is only started when a round of garbage collection is started, so not all of the object's Finalize () methods will be executed;  2) The thread is also a daemon thread, so if there are no other non-daemon threads in the virtual machine, Regardless of whether the thread has completed the Finalize () method, the JVM exits;  3) The JVM wraps the lost reference object into a finalizer object (implementation of the reference) when garbage collected, and puts it into Referencequeue, Handled by the finalizer thread; Finally, the reference to the finalizer object is set to null, reclaimed by the garbage collector;  4) Why does the JVM use a single thread to execute the Finalize () method? If the JVM's garbage collection thread is doing it by itself, it is likely that the GC thread will stop or be out of control due to a false operation in the Finalize () method, which is a disaster for GC threads;  Gang WORKER#0JVMJVM is used for new generation garbage collection (Monir GC) is a thread. #号后面是线程编号, for example: Gang worker#1  GC DAEMONJVMGC Daemon thread is the JVM for RMI provide remote distributed GC usage, the GC daemon thread will actively invoke the System.GC () method to perform full GC on the server. The intention is that when the RMI server returns an object to its client (the caller of the remote method), it tracks the use of the remote object in the client. When there are no more references to remote objects on the client, or if the reference "lease" expires and there is no update, the server will garbage reclaim the remote object.   However, we now have a-XX:+DISABLEEXPLICITGC configuration for the JVM boot parameters, so this thread is only soy sauce.   Idleremoverjbossjboss The connection pool has a minimum value, which is awakened by JBoss every time it is used to check and destroy idle and invalid connections in the connection pool until the remaining number of connections is less than or equal to its minimum value.   JAVA2D disposerjvm          This thread mainly serves the various components of AWT. Before talking about the main job responsibilities of this thread, we need to introduce the Disposer class. Disposer provides a AddRecord method. If you want to do some cleanup before an object is destroyed, you can call the Disposer#addrecord method, pass the object and a custom Disposerrecord interface implementation class, and enter it to register.              Disposer class will evoke "java2d disposer" thread, The thread scans whether the registered objects are being reclaimed, and if so, calls the Dispose method within the Disposerrecord implementation class for that object.             disposer is actually not limited to the AWT application scenario, but many of the components inside AWT need access to many operating system resources, so , these components need to be released before they are reclaimed.   insttoolcachescheduler_  quartzschedulerthreadquartz        InsttoolcaChescheduler_quartzschedulerthread is the main thread of quartz, which is responsible for getting the trigger to be triggered at the next point in time, and then executing the trigger-associated job.            principles are roughly as follows:            Spring and quartz are used in conjunction with a scenario where the spring IOC container is initialized to create and initialize the quartz thread pool (treadpool) and start it. Each thread in the thread pool is waiting when it starts, waiting for the outside world to assign runnable (the thread holding the Job object).            Then initializes and starts the main thread of the quartz (insttoolcachescheduler_ Quartzschedulerthread), the thread will be in a wait state since it was started. After waiting for the signal to be given to the outside world, the Run method of the main thread actually begins to work. Run will get jobstore the next job to be triggered, will wait until the job's true trigger time, and then wrap the job as a Jobrunshell object (the object implements the Runnable interface, In fact, it is the top treadpool waiting for the outside assigned to his runnable), and then the newly created Jobrunshell to the thread pool, the thread pool is responsible for the execution of the job. After the   thread pool receives the runnable, a thread from the thread pools starts runnable, and reflection calls the Run method in Jobrunshell, and after the Run method executes, Treadpool recycles the thread to the idle thread.   Insttoolcachescheduler_worker-2quartzinsttoolcachescheduler_worker-2 thread is a simple implementation of the threadpool thread, It is primarily responsible for allocating thread resources to execute   insttoolcachescheduler_quartzschedulerthread threads to its dispatch task (i.e. Jobrunshell).   jbosslifethreadjboss        JBoss Main thread starts successfully, Jbosslifethread thread is instantiated after the application is deployed, and Start,jbosslifethread thread is waiting after it is successfully started to maintain the JBoss The Java process is alive.   The more popular point is that after the JBoss startup process has been executed, why is it not over? It is because there is this thread that hold the master. Cow b Bar ~~  JBoss System Threads (1) -1jboss  the thread is a socket service, the default port number is: 1099. Primarily used to receive external naming service (jboss  JNDI) requests.   JCA poolfillerjboss    This thread is primarily hosting a connection pool for JBoss internal.   Brief introduction to how it works:      JBoss internal classes that have remote connection requirements need to implement managedconnectionfactory interfaces, such as the need to do a JDBC connection   Xamanagedconnectionfactory the object, the interface is implemented. It then wraps the Xamanagedconnectionfactory object, along with other information, into the Internalmanagedconnectionpool object, The Internalmanagedconnectionpool is then handed over to the queue within the Poolfiller object for management.    JCA Poolfiller Threads periodically determine if there is a Internalmanagedconnectionpool object in the queue that needs to be created and managed, and if so, call the Filltomin method of that object. Trigger it to create the appropriate remote connection and maintain the connection to its corresponding connection pool.   JDWP Event Helper threadjvm            JDWP is a communication interaction protocol, It defines the format in which information is passed between the debugger and the program being debugged. It defines the request command, the response data and the error code in detail, ensuring that the JVMTI and JDI of the front and back end are communicated smoothly.   This thread is primarily responsible for mapping the JDI event into a JVMTI signal to achieve the purpose of operating the JVM during commissioning.    
JDWP Transport LISTENER:DT_SOCKETJVM The thread is a Java Debugger listener thread responsible for handling the client's debug request. Usually we are accustomed to setting its listening port to 8787.   Low memory DETECTORJVM This thread is responsible for detecting the usable memory and allocating new memory space if it finds that the available RAM is lower.   Process reaperjvm    The thread is responsible for performing an OS command line operation.   Reference handlerjvm        JVM creates a Reference handler thread after the main thread is created, with the highest precedence, is 10, which is primarily used to handle garbage collection issues that refer to the object itself (soft references, weak references, virtual references).   Surrogate Locker thread (CMS) jvm          This thread is primarily used in conjunction with the CMS garbage collector, It is a daemon thread that is primarily responsible for handling GC processes where the Java layer's reference (refers to soft references, weak references, and so on) is synchronized with the state of the object at the internal level of the JVM. Here's a little introduction to their implementation: take Weakhashmap as an example, list some key points first (we'll string them all together later):  1.  we know HashMap use entry[] array to store the data, Weakhashmap is no exception, there is an entry[] array inside. The entry of   2.   Weakhashmap is very special, and its inheritance architecture is entry->weakreference->reference.   3.  Reference There is a global lock object: Lock, which is also known as pending_lock.    Note: It is a static object.   4.       reference  There is a static variable: pending.   5.  reference The polygon has a static inner class: The Referencehandler thread, which is initialized and started in the static block, waits in the wait state after the boot is complete, waiting in a lock synchronization lock module.   6.  In addition, Weakhashmap inside also instantiated a referencequeue queue, the role of this queue, will be mentioned later.   7.  The above key points are complete, we will string them up below.        Suppose that a reference to many objects has been saved inside the Weakhashmap object. When the JVM is doing a CMS GC, it creates a concurrentmarksweepthread (CMST) thread to perform the GC, The Concurrentmarksweepthread thread is created at the same time that it creates a surrogatelockerthread (abbreviated SLT) thread and starts it, after SLT is started, in the wait phase. When Cmst starts the GC, a message is sent to SLT to get the global lock for the Java Layer Reference object: lock. Until the CMS GC is complete, the JVM will place the WeakReference container object belonging to all the reclaimed objects in Weakhashmap into the pending attribute of reference (after each GC is complete, The pending property is essentially not null), and then notifies SLT to release and notify the global lock: lock. At this point, the Run method of the Referencehandler thread is activated, leaving it out of the wait state and starting to work. Referencehandler This thread will move all WeakReference objects in the pending into their respective queues, such as the current weakreference belongs to a Weakhashmap object, Then it will be put into the corresponding Referencequeue queue (the queue is the list structure). The next time we get from the Weakhashmap object, put data, or call the size method, Weakhashmap will referencequeue in the queue WeakReference poll out and entry[] Data is compared, if found the same, it means that the entry saved objects have been GC off, then entry[] within the entry object removed.   taskobjecttimerfactoryjvm          as the name implies, this thread is used to perform the task. When we put a thought to the timer object and tell it the execution time, cycle time, the timer will put the task into the task queue, and notify the taskobjecttimerfactory thread to handle the task, The taskobjecttimerfactory thread removes a task that has a status of canceled from the task queue, and if the task is a non-repeating type of execution, it is removed from the task queue after the task has been executed, and if the task needs to be repeated, it calculates the point in time for the next execution.   VM Periodic task threadjvm        This thread is a thread that is scheduled by the JVM's recurring task, which is created by Watcherthread, is a singleton object. This thread is used more frequently within the JVM, such as regular memory monitoring, JVM health monitoring, and we often need to execute some JSTAT commands to view the GC, as follows:  Jstat-gcutil 23483 7   This command tells the JVM to print the PID in the console at 23483 for the GC case, which is printed 250 milliseconds at a time and prints 7 times altogether.   VM threadjvm         This thread compares cow B, which is the thread matrix inside the JVM, According to the note in the Hotspot source code (VMTHREAD.HPP), it is a singleton object (the most primitive thread) that produces or triggers all other threads, and this single VM thread is used by other threads to do some VM operations (such as cleaning up garbage, etc.).            There is a vmoperationqueue queue in the vmthread structure, all VM threading operations (VM_ Operation) will be saved in this queue, vmthread itself is a thread, and its thread is responsible for executing a self-polling loop function (refer to: VMThread.cpp inside the Void Vmthread::loop ()), The loop function removes the currently required operand from the Vmoperationqueue queue by priority (Vm_operation), and calls the Vm_operation->evaluate function to execute the business logic of the operation type itself.          PS:VM operation type is defined in the Vm_operations.hpp file, listing several: Threadstop, Threaddump, Printthreads, Gencollectfull, Gencollectfullconcurrent, Cms_initial_mark, Cms_final_remark ..... Interested students, you can go to view the source files.   (transported from http://blog.csdn.net/a43350860/article/details/8134234 thanks to the original author)  
2. Jmap 2.1 Gets the details of the memory allocation for running the Java program. such as the number of instances, size, etc.
2.2 Named Row format jmap [option] PID jmap [option] executable core jmap [option] [email protected]]remote-hostname-or-i P
-dump:[live,]format=b,file=<filename> uses the Hprof binary form to output the JVM's heap content to File =.  The live sub-option is optional, and if you specify the live option, only the live object is exported to the file.  -finalizerinfo prints information about objects that are waiting to be reclaimed.  -heap prints the summary of the heap, the algorithm used by the GC, the configuration of the heap, and the use of the wise heap. -histo[:live] Prints the number of instances per class, memory consumption, class full name information. The internal class name of the VM is prefixed with "*".  If the live child parameter is added, only the number of live objects is counted. -permstat Prints the classload and JVM heap for a long layer of information. Contains the name of each classloader, the liveliness, the address, the parent ClassLoader, and the number of classes loaded.  In addition, the number of internal strings and the amount of memory consumed are also printed. -F coercion. Use the-dump or-histo parameters when the PID is not appropriate.  In this mode, the live sub-argument is invalid. -H | -HELP Print auxiliary Information-j Pass parameters to Jmap-initiated JVM.
2.3 Use example Jmap-histo PID (view instance)
Jmap-dump:format=b,file=heap.bin PID (export memory, it is said to have an impact on performance, careful use) (Format=b is through the binary meaning, but can not export text files I did not find, know to tell me)  The memory structure is all dump into the binary file, and the memory structure can be analyzed by IBM's Heapanalyzer and Eclipse's Memoryanalyzer. This is the memory structure of our daily, which I looked at with Heapanalyzer, and we have listed the possible problems. (This tool I am not familiar with, only for the reference of You)
Here's how I use Eclipse's memoryanalyzer to view the memory structure

Above is the analysis of the Eclipse analysis memory leak. This feature is a lot of points. Can learn slowly
3. Jstat 3.1 This is a more practical command that can be used to observe CLASSLOADER,COMPILER,GC related information. Ability to monitor resources and performance at all times
3.2 Command format-class: Statistics class loader behavior Information-compile: Statistical compilation Behavior Information-GC: Statistics of JDK GC when heap information-gccapacity: Statistics different generations (do not know how to translate well, including New district, old age area, Permanent district) the corresponding heap capacity situation-gccause: Statistics GC, (same-gcutil) and the event that caused the GC-gcnew: When statistical GC, the Cenozoic situation-gcnewcapacity: When the GC is counted, Cenozoic Heap Capacity-gcold: Statistics GC, the situation of the elderly area-gcoldcapacity: Statistics GC, old age area heap capacity-gcpermcapacity: Statistical GC, permanent area heap capacity-gcutil: When statistical GC, Heap condition
3.3 Output parameter content S0-heap Survivor space 0 has been used as a percentage s0c:s0 the size of the current capacity s0u:s0 the size s1-heap the Survivor space 1 has been used Percent S1C:S1 the size of the current capacity s1u:s1 already used in the size e-heap the Eden space area has been used as a percentage of the space Ec:eden space current capacity Eu:eden space has used the size O  The percentage of the old space in the heap that has been used by oc:old spaces the size of the current capacity ou:old space has been used p-perm the percentage of space that has been used oc:perm space's current capacity Ou:perm space already used size ygc-the number of young GC occurrences from application startup to sampling ygct– the time (in seconds) spent by the young GC from application startup to sampling fgc-full GC occurs from application startup to sampling Number of times fgct– the time (in seconds) spent in the full GC from the application startup to sampling, gct-the total time (in seconds) that was used for garbage collection from the application startup to sampling, with a value equal to YGC+FGC
Example 1
Example 2 (5 consecutive times)
Example 3 (PGCMN shows the minimum perm memory usage, PGCMX shows the maximum memory usage of perm, the PGC is the current newly generated perm memory footprint, the PC is but the former Perm memory footprint) This tool has a lot of parameters, It is said that basically can cover all the functions of jprofile and other charge tools. Multi-use is very helpful for system tuning.
Note 1: We use the-f parameter when we use this command in daily. Because our users are not users of the start command note 2:daily These commands do not seem to be configured in the environment variables, this is what I see in my application machine. Need to go under the JDK directory to execute. Sudo is a must, of course.

View the JDK thread log

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.