Sunday, 21 August 2016

THREAD DUMP

•Thread dumps are one of the primary and most resourceful pieces of data used for debugging.
•Can be used in a variety of scenarios for debugging all java based applications. 
•Thread dumps primarily used to debug run-time state of a JVM (Java Virtual Machine).
•Thread dump is a real-time snapshot of JVM processing.

•Snapshot of all threads in the JVM process.
•Provides the state of each thread along with the stack trace associated with the same.
•Thread stack contains the method execution sequence that the thread has undertaken till that point in time.
•The stack populates with sequential method execution. 
•The stack unwinds when the methods return in a reverse sequence.
•Thread dump reveals information about the application’s thread activity as well.

THREAD STATES

•NEW – The thread is created, but not yet started. 
•RUNNABLE – The thread is currently executing in the JVM.
•BLOCKED – The thread is blocked waiting for a monitor lock.
•WAITING – The thread is waiting indefinitely for another thread to perform some action.
•TIMED_WAITING – The thread is waiting for a specified time for another thread to perform some action
TERMINATED – The thread has exited

DIFFERENT WAYS TO TAKE THREAD DUMP

Picture
 
 
 
 
 
Use operating system commands to get the thread dumps when WLS starts up from a command-line script:
    • On Windows OSes, thread dumps can be created by
      <ctrl>+<break> -- the thread dumps are generated in the server stdout
The Thread dump will be printed in the cmd prompt where you have started the server


    • On POSIX-compliant platforms (e.g. Solaris and Linux), first identify the process ID (pid) using ps -ef | grep java, then run
      kill -3 <pid> 2>&1
      Signal 3 is equivalent to SIGQUIT. Note that in Solaris, the thread dump is generated in the current shell, but in Linux, the thread dump is generated in the shell which started the java process specified by the pid

Picture











2. Using weblogic.WLST:
setDomain.cmd or setDomain.sh depending on the OS
java weblogic.WLST
connect("<username>","<password>","t3://<url>:<port>")
threadDump()


Picture











The thread dump will be generated in Thread_Dump_AdminServer.txt.  at the location C:\Oracle\Middleware\wlserver_10.3\common\bin


If you want to take the thread dump of the Managed Server then connect to the managed Server by using the port number of the managed Server and then execute the threadDump Command .

Picture











Picture











The thread Dump of the Managed Server will be present at the location

The thread dump will be generated in Thread_Dump_MS1.txt.  at the location C:\Oracle\Middleware\wlserver_10.3\common\bin

Picture











3. Thread Dump can be generated by using the Weblogic Admin utility setDomain.cmd or setDomain.sh depending on the OS
java weblogic.Admin <url>:<port> -username <username> -password <password> THREAD_DUMP
The thread dump will be generated in the defined server stdout.
Command to take thread dump for  Admin Server
C:\Oracle\Middleware\user_projects\domains\base_domain>java weblogic.Admin -url
t3://localhost:7001 -username weblogic -password weblogic1 THREAD_DUMP


Command to take thread dump in Managed Server Just change the port number 
C:\Oracle\Middleware\user_projects\domains\base_domain>java weblogic.Admin -url
t3://localhost:7003 -username weblogic -password weblogic1 THREAD_DUMP

Picture











4..From the WLS Administration Console, a thread dump can be created by navigating toServer -> <server_name> -> Monitoring ->Threads -> Dump threads stack. This method could lead to truncated or incomplete thread dumps


Picture










5.With jstack in Sun HotSpot
jstack <pid> or jstack -l <pid> to print additional information about locks

6.From the JRockit command line:
jrcmd <pid> print_threads

Tools for Analysis of Thread dumps

ThreadLogic  - The most powerful tool for thread dump analysis. Useful to mine thread dumps in addition to providing advisories based on pattern analysis. Great support for WLS. Developed by Oracle A-Team.
Samurai – A pretty old but useful utility to analyze multiple thread dumps.
Thread Dump analyzers provided by multiple vendors. IBM JCA Thread Analyzer being a good example. 
Notepad – probably the best way to look at thread dumps to try and get to understand the nitty-gritty of analysis.

No comments:

Post a Comment