Skip to content

Commit

Permalink
Issue #000 fix: threaddump api.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahesh Kumar Gangula committed Jun 11, 2018
1 parent 39defbb commit c4fb45d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
51 changes: 51 additions & 0 deletions service/app/controllers/ThreadDumpController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package controllers;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;

import org.sunbird.actor.router.BackgroundRequestRouter;
import org.sunbird.actor.service.SunbirdMWService;
import org.sunbird.common.request.Request;

import play.libs.F.Promise;
import play.mvc.Result;

/**
*
* @author Mahesh Kumar Gangula
*
*/

public class ThreadDumpController extends BaseController {

public Promise<Result> threaddump() {
final StringBuilder dump = new StringBuilder();
final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
final ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 100);
for (ThreadInfo threadInfo : threadInfos) {
dump.append('"');
dump.append(threadInfo.getThreadName());
dump.append("\" ");
final Thread.State state = threadInfo.getThreadState();
dump.append("\n java.lang.Thread.State: ");
dump.append(state);
final StackTraceElement[] stackTraceElements = threadInfo.getStackTrace();
for (final StackTraceElement stackTraceElement : stackTraceElements) {
dump.append("\n at ");
dump.append(stackTraceElement);
}
dump.append("\n\n");
}
System.out.println("=== thread-dump start ===");
System.out.println(dump.toString());
System.out.println("=== thread-dump end ===");
Request request = new Request();
request.setOperation("takeThreadDump");
request.setEnv(getEnvironment());
if ("off".equalsIgnoreCase(BackgroundRequestRouter.getMode())) {
actorResponseHandler(SunbirdMWService.getBackgroundRequestRouter(), request, timeout, null, request());
}
return Promise.promise(() -> ok("successful"));
}
}
1 change: 1 addition & 0 deletions service/conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ GET /v1/user/retire @controllers.LearnerController.getHealth()
GET /v1/org/member/suspend @controllers.LearnerController.getHealth()
POST /v1/org/search @controllers.organisationmanagement.OrganisationController.search()
GET /health @controllers.healthmanager.HealthController.getHealth()
GET /threaddump @controllers.ThreadDumpController.threaddump()

#bulk upload

Expand Down

0 comments on commit c4fb45d

Please sign in to comment.