use of java.lang.management.ThreadInfo in project pinpoint by naver.
the class AgentEventMessageSerDesTest method createTCommandThreadDumpResponse.
private TCommandThreadDumpResponse createTCommandThreadDumpResponse() {
final TCommandThreadDumpResponse threadDumpResponse = new TCommandThreadDumpResponse();
ThreadInfo[] threadInfos = ThreadMXBeanUtils.dumpAllThread();
for (ThreadInfo threadInfo : threadInfos) {
final TThreadDump threadDump = createTThreadDump(threadInfo);
threadDumpResponse.addToThreadDumps(threadDump);
}
return threadDumpResponse;
}
use of java.lang.management.ThreadInfo in project pinpoint by naver.
the class ThreadMXBeanUtils method findThread.
public static List<ThreadInfo> findThread(String threadName) {
Asserts.notNull(threadName, "threadName may not be null.");
ThreadInfo[] threadInfos = dumpAllThread();
if (threadInfos == null) {
return Collections.emptyList();
}
ArrayList<ThreadInfo> threadInfoList = new ArrayList<ThreadInfo>(1);
for (ThreadInfo threadInfo : threadInfos) {
if (threadName.equals(threadInfo.getThreadName())) {
threadInfoList.add(threadInfo);
}
}
return threadInfoList;
}
use of java.lang.management.ThreadInfo in project pinpoint by naver.
the class ThreadDumpService method requestCommandService.
@Override
public TBase<?, ?> requestCommandService(TBase tbase) {
logger.info("{} execute {}.", this, tbase);
TCommandThreadDump param = (TCommandThreadDump) tbase;
TThreadDumpType type = param.getType();
List<ThreadInfo> threadInfoList = null;
if (TThreadDumpType.TARGET == type) {
threadInfoList = getThreadInfo(param.getName());
} else if (TThreadDumpType.PENDING == type) {
threadInfoList = getThreadInfo(param.getPendingTimeMillis());
} else {
threadInfoList = Arrays.asList(getAllThreadInfo());
}
TCommandThreadDumpResponse response = new TCommandThreadDumpResponse();
for (ThreadInfo info : threadInfoList) {
TThreadDump dump = new TThreadDump();
dump.setThreadName(info.getThreadName());
dump.setThreadId(info.getThreadId());
dump.setBlockedTime(info.getBlockedTime());
dump.setBlockedCount(info.getBlockedCount());
dump.setWaitedTime(info.getWaitedTime());
dump.setWaitedCount(info.getWaitedCount());
dump.setLockName(info.getLockName());
dump.setLockOwnerId(info.getLockOwnerId());
dump.setLockOwnerName(info.getLockOwnerName());
dump.setInNative(info.isInNative());
dump.setSuspended(info.isSuspended());
dump.setThreadState(getThreadState(info));
StackTraceElement[] stackTraceElements = info.getStackTrace();
for (StackTraceElement each : stackTraceElements) {
dump.addToStackTrace(each.toString());
}
MonitorInfo[] monitorInfos = info.getLockedMonitors();
for (MonitorInfo each : monitorInfos) {
TMonitorInfo tMonitorInfo = new TMonitorInfo();
tMonitorInfo.setStackDepth(each.getLockedStackDepth());
tMonitorInfo.setStackFrame(each.getLockedStackFrame().toString());
dump.addToLockedMonitors(tMonitorInfo);
}
LockInfo[] lockInfos = info.getLockedSynchronizers();
for (LockInfo lockInfo : lockInfos) {
dump.addToLockedSynchronizers(lockInfo.toString());
}
response.addToThreadDumps(dump);
}
return response;
}
use of java.lang.management.ThreadInfo in project druid by alibaba.
the class Case1 method p0.
private void p0(final DataSource dataSource, String name, int threadCount) throws Exception {
final CountDownLatch startLatch = new CountDownLatch(1);
final CountDownLatch endLatch = new CountDownLatch(threadCount);
final CountDownLatch dumpLatch = new CountDownLatch(1);
Thread[] threads = new Thread[threadCount];
for (int i = 0; i < threadCount; ++i) {
Thread thread = new Thread() {
public void run() {
try {
startLatch.await();
for (int i = 0; i < LOOP_COUNT; ++i) {
Connection conn = dataSource.getConnection();
conn.close();
}
} catch (Exception ex) {
ex.printStackTrace();
}
endLatch.countDown();
try {
dumpLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
threads[i] = thread;
thread.start();
}
long startMillis = System.currentTimeMillis();
long startYGC = TestUtil.getYoungGC();
long startFullGC = TestUtil.getFullGC();
startLatch.countDown();
endLatch.await();
long[] threadIdArray = new long[threads.length];
for (int i = 0; i < threads.length; ++i) {
threadIdArray[i] = threads[i].getId();
}
ThreadInfo[] threadInfoArray = ManagementFactory.getThreadMXBean().getThreadInfo(threadIdArray);
dumpLatch.countDown();
long blockedCount = 0;
long waitedCount = 0;
for (int i = 0; i < threadInfoArray.length; ++i) {
ThreadInfo threadInfo = threadInfoArray[i];
blockedCount += threadInfo.getBlockedCount();
waitedCount += threadInfo.getWaitedCount();
}
long millis = System.currentTimeMillis() - startMillis;
long ygc = TestUtil.getYoungGC() - startYGC;
long fullGC = TestUtil.getFullGC() - startFullGC;
System.out.println("thread " + threadCount + " " + name + " millis : " + NumberFormat.getInstance().format(millis) + "; YGC " + ygc + " FGC " + fullGC + " blocked " + //
NumberFormat.getInstance().format(blockedCount) + " waited " + NumberFormat.getInstance().format(waitedCount) + " physicalConn " + physicalConnStat.get());
}
use of java.lang.management.ThreadInfo in project druid by alibaba.
the class Case2 method p0.
private void p0(final DataSource dataSource, String name, int threadCount) throws Exception {
final CountDownLatch startLatch = new CountDownLatch(1);
final CountDownLatch endLatch = new CountDownLatch(threadCount);
final AtomicLong blockedStat = new AtomicLong();
final AtomicLong waitedStat = new AtomicLong();
for (int i = 0; i < threadCount; ++i) {
Thread thread = new Thread() {
public void run() {
try {
startLatch.await();
long threadId = Thread.currentThread().getId();
long startBlockedCount, startWaitedCount;
{
ThreadInfo threadInfo = ManagementFactory.getThreadMXBean().getThreadInfo(threadId);
startBlockedCount = threadInfo.getBlockedCount();
startWaitedCount = threadInfo.getWaitedCount();
}
for (int i = 0; i < LOOP_COUNT; ++i) {
Connection conn = dataSource.getConnection();
conn.close();
}
ThreadInfo threadInfo = ManagementFactory.getThreadMXBean().getThreadInfo(threadId);
long blockedCount = threadInfo.getBlockedCount() - startBlockedCount;
long waitedCount = threadInfo.getWaitedCount() - startWaitedCount;
blockedStat.addAndGet(blockedCount);
waitedStat.addAndGet(waitedCount);
} catch (Exception ex) {
ex.printStackTrace();
}
endLatch.countDown();
}
};
thread.start();
}
long startMillis = System.currentTimeMillis();
long startYGC = TestUtil.getYoungGC();
long startFullGC = TestUtil.getFullGC();
startLatch.countDown();
endLatch.await();
long millis = System.currentTimeMillis() - startMillis;
long ygc = TestUtil.getYoungGC() - startYGC;
long fullGC = TestUtil.getFullGC() - startFullGC;
System.out.println("thread " + threadCount + " " + name + " millis : " + NumberFormat.getInstance().format(millis) + ", YGC " + ygc + " FGC " + fullGC + " blockedCount " + blockedStat.get() + " waitedCount " + waitedStat.get());
}
Aggregations