Saturday, 23 April 2011

Thread Dump And Heap Dump


Weblogic Thread Dump and Heap Dump ?


Weblogic Thread Dump

Thread

Before starting discussion on Thread Dump, Lets first discuss on thread, What is thread exactly it does.

Ok, Lets start with the official definition first - 

thread is a thread of execution in a program. The Java Virtual Machine allows an application to have multiple threads of execution running concurrently.

Basically, for every process or program to run on computer we need the system resources like cpu time, RAM etc, it's the thread which which is created by the system for each and every process/program to be executed, it means your system took a small portion of your system resources and assign to that thread, then then thread execute the respective program or process and release the thread or you can say system resources. So, in case of java programs, if your program run as a single threaded then it could be problematic situations for you because if multiple requests are there then the thread would keep all the requests in the queue till finish the current job. On the other hand, if you have multithreaded capabilities then there will be multiple threads to handle multiple requests in parallel, but only the drawback is each thread will be assigned with some system resources as I said earlier So, you have to make sure on thread counts also.  

Same issues happened with weblogic also when situation arises to take and analyze the thread dumps. With weblogic 8.x and old versions you have the capabilities to define the maximum number of threads for processing but 9.x on wards it has been changed and new concept of thread pool introduced where the size of threads create automatically according to the need. 

Thread Dump

So, specific to weblogic, sometimes your weblogic server stop to respond and chewed your complete heap you have defined for the server then, in that condition you have to take the thread dumps multiple times within seconds on minute of interval, this is because, as I said earlier each thread took the resources and since weblogic created the multiple threads so, sometimes some or all threads stuck for some requests or on process and started taking your remaining system resources and a condition come when it stuck and stop processing, that time you have to take the thread dumps, So, When we trigger a thread dump on an application server, all active thread information will be dumped into file which is normally known as thread dump. In this dump file, we can get information about thread like active thread, hung thread, dead lock, runnable and inactive thread info, and then you can analyze the request being in process which cause thread to be stuck, hung, dead etc.


Heap Dump

We know that we define heap for each of the created managed or admin server since each server is running on it's own jvm and during the access and processing of a particular request, java objects are created inside the jvm heap, so when we take the heap dump it takes the snapshot of the jvm heap which includes the java objects and classes inside the heap at that particular time when heap dump taken.
  









Friday, 8 April 2011

WLST : Encrypt the credentials when running WLST in interactive or script mode


If you want to get away from providing user name and password in plain text when using WLST. WebLogic Server provides a way to encrypt the credentials for server start up. You can create a password file "boot.properties" (called as Boot Identity File) with plain text credentials in a folder named security under the server root directory. This file will be automatically detected during the server start up and the server will encrypt the information in this file for subsequent use. Until WebLogic Server 9.x this file should be placed under the DOMAIN folder. So servers sharing the same file system share the same boot identity file and cannot be configured to use different files.
This boot identity file can also be used by WLST only when started from the domain folder. This is mainly because the domain's password key (SerializedSystemIni.dat) is used to encrypt this file. 
If you are using WLST from a different location or from a remote machine to connect to the server or if you want to run WLST script you can use a different technique. You can use WLST to generate a User Configuration file which will have encrypted user name and password using storeUserConfig() command. A key file that will be used to encrypt the data will also get generated along with the user config file. The key file is important as it is required to decrypt the values back from the user config file. This is an online WLST command. So you should be connected to a running WebLogic Server or a Node Manager to issue this command.
When you use this command with no arguments the user configuration file for the current user will be generated within the current OS user's home folder.

wls:/testdomain/serverConfig>storeUserConfig()

You can also specify the location and name for the key file and the userconfig file if you want them to be created elsewhere.
wls:/testdomain/serverConfig>storeUserConfig('/usr/home/user1/configfile.secure', '/usr/home/user1/keyfile.secure')

If the files are stored with the default name (osusername-WebLogicConfig.properties & osusername-WebLogicKey.properties) you can simply connect without specifying the username and password in the connect() command.
wls:/offline> connect(url='t3://host:port')

If the files are stored in a different location or with a different name, then they can be passed as an argument to the connect() command 
wls:/offline> connect(userConfigFile='/usr/home/user1/configfile.secure', userKeyFile='/usr/home/user1/keyfile.secure', url='t3://host:port')
or connect with node manager like below

nmConnect (userConfigFile='/usr/home/user1/configfile.secure',userKeyFile='/usr/home/user1/keyfile.secure',host='HOSTNAME',port='PORT',domainName='DOMAIN_NAME',domainDir='DOMAIN_DIR_PATH',nmType='plain')