Wednesday, April 30, 2014

What is Salesforce Trigger

Salesforce Trigger:-

Salesforce trigger is apex code that executes before or after the folowing types of operations.
  • insert    -  You can have this trigger run  before or after objects records are inserted into database.
  • update  -  You can have this trigger run  before or after objects records are updated into database.
  • delete   -  You can have this trigger run  before or after objects records are deleted from  database.
  • merge   -  Merge events do not fire their own trigger events. Instead, they fire delete and update event
  • upsert   -  Fire both before and after insert or before and after update triggers as  appropriate
  • undelete- record is restored from the Recycle Bin 

I will be explaining each trigger with example in next tutorial.

Tuesday, April 22, 2014

Sonar and Sonar runner with Jenkins

Configure  Sonar and Sonar runner with Jenkins

1)Install sonar plugin in jenkins
2)Download sonarqube( and unzip it  into C:\KB\sonar\sonarqube-4.1.2
3)Open file from conf folder and uncomment below properties


you will have to create sonar database

4))Open command prompt and type cd  C:\KB\sonar\sonarqube-4.1.2\bin\windows-x86-64

5) Run StartSonar.bat

6) Configure sonar through manage jenkins->configure system

7))Download sonar runner and unzip it intoC:\KB\sonar\sonar-runner-2.3
8)Open file from bin folder.
add this line at start below set ERROR_CODE=0
set SONAR_RUNNER_HOME=C:\KB\sonar\sonar-runner-2.3
and replace existing set  PROJECT_HOME with set PROJECT_HOME=C:\Jenkins\jobs\\workspace\
9)Configure sonar through manage jenkins->configure system

10) Now open job configuration from jenkins for which you want to run sonar
 and in Add Build Step select Invoke Standalone Sonar Analysis

11)Save the configuration  and then run the build for job.

Monday, April 7, 2014

How To Kill Tomcat HTTP Stuck Thread

Stuck Thread Problem:

In one of our application we were facing issue of stuck thread,it can not complete current work and also not able to accept new work.

Once thread is stuck,CPU utilization starts increasing slowly, as stucked thread is utilizing more CPU, other threads start performing slowly makes the environment slow for users  and at some point it brings your server down.

Restarting server in business hours is not good for anyone ,and it creates the bad impression of IT department to business.

Identify Stuck Threads:

To identify which are stuck threads ,you can use jconsole and  topthreads plugin.once you identified the top http threads which are consuming more memory you can kill stuck threads using below solution.

Stuck Thread Solution:
so we have implemented below solution for stuck thread which we found on web.

in java you can create jsp with below code and call jsp using URL something like this-

<%@page language="java"%>
     String threadNameToKill = request.getParameter("threadName");
     killThread(threadNameToKill, out);
     public void killThread(String threadNameToKill, JspWriter out) throws Exception {
         ThreadGroup root = Thread.currentThread().getThreadGroup().getParent();
         while (root.getParent() != null) {
             root = root.getParent();
         visit(root, 0, threadNameToKill,out);

    public void visit(ThreadGroup group, int level, String threadNameToKill,JspWriter out) throws Exception {
         int numThreads = group.activeCount();
         Thread[] threads = new Thread[numThreads * 2];
         numThreads = group.enumerate(threads, false);
         for (int i = 0; i < numThreads; i++) { // Get thread
             Thread thread = threads[i];
             if (threadNameToKill.equals(thread.getName())) {
Thread " + threadNameToKill + " stopped. It should disappear from threads list in few seconds...");
         int numGroups = group.activeGroupCount();
         ThreadGroup[] groups = new ThreadGroup[numGroups * 2];
         numGroups = group.enumerate(groups, false);
         for (int i = 0; i < numGroups; i++) {
             visit(groups[i], level + 1, threadNameToKill, out);