-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mahesh Kumar Gangula
committed
Jun 11, 2018
1 parent
39defbb
commit c4fb45d
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters