java.lang.management.ThreadMXBean Java Examples
The following examples show how to use
java.lang.management.ThreadMXBean.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JvmThreadInstanceEntryImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Getter for the "JvmThreadInstCpuTimeNs" variable. */ public Long getJvmThreadInstCpuTimeNs() throws SnmpStatusException { long l = 0; final ThreadMXBean tmb = JvmThreadingImpl.getThreadMXBean(); try { if (tmb.isThreadCpuTimeSupported()) { l = tmb.getThreadCpuTime(info.getThreadId()); log.debug("getJvmThreadInstCpuTimeNs", "Cpu time ns : " + l); //Cpu time measurement is disabled or the id is not valid. if(l == -1) l = 0; } } catch (UnsatisfiedLinkError e) { // XXX Revisit: catch TO BE EVENTUALLY REMOVED log.debug("getJvmThreadInstCpuTimeNs", "Operation not supported: " + e); } return new Long(l); }
Example #2
Source File: DefaultCoreEnvironmentTest.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
private static Set<String> getCouchbaseThreads() { final ThreadMXBean threadManager = ManagementFactory.getThreadMXBean(); final ThreadInfo[] threads = threadManager.getThreadInfo(threadManager.getAllThreadIds()); final Set<String> result = new HashSet<>(); for (ThreadInfo t : threads) { if (t == null || t.getThreadName() == null || t.getThreadState() == Thread.State.TERMINATED) { continue; // thread already dead, or anonymous (not one of ours) } String name = t.getThreadName(); if (name.startsWith("cb-") || name.contains("Rx")) { result.add(t.getThreadId() + ":" +t.getThreadName()); } } return result; }
Example #3
Source File: JvmThreadInstanceEntryImpl.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * Getter for the "JvmThreadInstCpuTimeNs" variable. */ public Long getJvmThreadInstCpuTimeNs() throws SnmpStatusException { long l = 0; final ThreadMXBean tmb = JvmThreadingImpl.getThreadMXBean(); try { if (tmb.isThreadCpuTimeSupported()) { l = tmb.getThreadCpuTime(info.getThreadId()); log.debug("getJvmThreadInstCpuTimeNs", "Cpu time ns : " + l); //Cpu time measurement is disabled or the id is not valid. if(l == -1) l = 0; } } catch (UnsatisfiedLinkError e) { // XXX Revisit: catch TO BE EVENTUALLY REMOVED log.debug("getJvmThreadInstCpuTimeNs", "Operation not supported: " + e); } return new Long(l); }
Example #4
Source File: DebugUtils.java From weblaf with GNU General Public License v3.0 | 6 votes |
/** * Returns deadlocked threads stack trace. * * @return deadlocked threads stack trace */ @NotNull public static String getDeadlockStackTrace () { final ThreadMXBean bean = ManagementFactory.getThreadMXBean (); final long[] threadIds = bean.findDeadlockedThreads (); final StringBuilder stackTrace = new StringBuilder (); if ( threadIds != null ) { final ThreadInfo[] infos = bean.getThreadInfo ( threadIds ); for ( final ThreadInfo info : infos ) { final StackTraceElement[] stack = info.getStackTrace (); stackTrace.append ( ExceptionUtils.getStackTrace ( stack ) ); stackTrace.append ( info != infos[ infos.length - 1 ] ? "\n" : "" ); } } return stackTrace.toString (); }
Example #5
Source File: AutoScalerPolicyTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
public static void dumpThreadsEtc() { ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); ThreadInfo[] threads = threadMXBean.dumpAllThreads(true, true); for (ThreadInfo thread : threads) { System.out.println(thread.getThreadName()+" ("+thread.getThreadState()+")"); for (StackTraceElement stackTraceElement : thread.getStackTrace()) { System.out.println("\t"+stackTraceElement); } } MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage(); MemoryUsage nonHeapMemoryUsage = memoryMXBean.getNonHeapMemoryUsage(); System.out.println("Memory:"); System.out.println("\tHeap: used="+heapMemoryUsage.getUsed()+"; max="+heapMemoryUsage.getMax()+"; init="+heapMemoryUsage.getInit()+"; committed="+heapMemoryUsage.getCommitted()); System.out.println("\tNon-heap: used="+nonHeapMemoryUsage.getUsed()+"; max="+nonHeapMemoryUsage.getMax()+"; init="+nonHeapMemoryUsage.getInit()+"; committed="+nonHeapMemoryUsage.getCommitted()); OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); System.out.println("OS:"); System.out.println("\tsysLoadAvg="+operatingSystemMXBean.getSystemLoadAverage()+"; availableProcessors="+operatingSystemMXBean.getAvailableProcessors()+"; arch="+operatingSystemMXBean.getArch()); }
Example #6
Source File: ManagementFactoryTest.java From banyan with MIT License | 6 votes |
public static void main(String[] args) { ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); List<GarbageCollectorMXBean> garbageCollectorMXBeanList = ManagementFactory.getGarbageCollectorMXBeans(); for (GarbageCollectorMXBean gcMXBean : garbageCollectorMXBeanList) { String gcName = gcMXBean.getName(); String memoryPoolNames[] = gcMXBean.getMemoryPoolNames(); for (String memoryPoolName : memoryPoolNames) { System.out.println(memoryPoolName); } ObjectName objectName = gcMXBean.getObjectName(); String domainName = objectName.getDomain(); System.out.println(domainName+"__"+objectName.getCanonicalName()); System.out.println(gcName); } //不需要获取同步的monitor 和 synchronize信息,仅获取线程和线程堆栈信息。 ThreadInfo[] allThreads = threadMXBean.dumpAllThreads(true, true); for (ThreadInfo threadInfo : allThreads) { String threadName = threadInfo.getThreadName(); long threadId = threadInfo.getThreadId(); System.out.println(threadName + "," + threadId + "," + threadInfo.getLockOwnerName()); } }
Example #7
Source File: ThreadLauncherDaemonTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void dumpStateWhileWaiting( long lWait ) throws InterruptedException { // wait for the daemon to have a chance to try running Thread.sleep( lWait ); 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" ); } AppLogService.info( "Current state : " + dump ); }
Example #8
Source File: ThreadMXBeanThreadInfoHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { validator.validate(operation); ThreadMXBean mbean = ManagementFactory.getThreadMXBean(); try { long id = operation.require(PlatformMBeanConstants.ID).asLong(); ThreadInfo info; if (operation.hasDefined(PlatformMBeanConstants.MAX_DEPTH)) { info = mbean.getThreadInfo(id, operation.require(PlatformMBeanConstants.MAX_DEPTH).asInt()); } else { info = mbean.getThreadInfo(id); } final ModelNode result = context.getResult(); if (info != null) { result.set(PlatformMBeanUtil.getDetypedThreadInfo(info, mbean.isThreadCpuTimeSupported())); } } catch (SecurityException e) { throw new OperationFailedException(e.toString()); } }
Example #9
Source File: ConnectorStopDeadlockTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
static void waitForBlock(Thread t) { Thread currentThread = Thread.currentThread(); System.out.println("waiting for thread " + t.getName() + " to block " + "on a lock held by thread " + currentThread.getName()); ThreadMXBean tm = ManagementFactory.getThreadMXBean(); while (true) { ThreadInfo ti = tm.getThreadInfo(t.getId()); if (ti == null) { System.out.println(" thread has exited"); return; } if (ti.getLockOwnerId() == currentThread.getId()) { System.out.println(" thread now blocked"); return; } Thread.yield(); } }
Example #10
Source File: JMServer.java From jmonitor with GNU General Public License v2.0 | 6 votes |
@HttpMapping(url = "/deadlockCheck") public JSONObject doDeadlockCheck(Map<String, Object> param) { try { String app = ((HttpServletRequest) param.get(JMDispatcher.REQ)).getParameter("app"); ThreadMXBean tBean = JMConnManager.getThreadMBean(app); JSONObject json = new JSONObject(); long[] dTh = tBean.findDeadlockedThreads(); if (dTh != null) { ThreadInfo[] threadInfo = tBean.getThreadInfo(dTh, Integer.MAX_VALUE); StringBuffer sb = new StringBuffer(); for (ThreadInfo info : threadInfo) { sb.append("\n").append(info); } json.put("hasdeadlock", true); json.put("info", sb); return json; } json.put("hasdeadlock", false); return json; } catch (IOException e) { throw new RuntimeException(e); } }
Example #11
Source File: GetInternalThreads.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { long value = mbean.getInternalThreadCount(); if (value < MIN_VALUE_FOR_PASS || value > MAX_VALUE_FOR_PASS) { throw new RuntimeException("Internal thread count " + "illegal value: " + value + " " + "(MIN = " + MIN_VALUE_FOR_PASS + "; " + "MAX = " + MAX_VALUE_FOR_PASS + ")"); } System.out.println("Internal Thread Count = " + value); ThreadMXBean thread = ManagementFactory.getThreadMXBean(); if (!thread.isThreadCpuTimeSupported()) { System.out.println("Thread Cpu Time is not supported."); return; } while(!testCPUTime()) { Thread.sleep(100); } }
Example #12
Source File: JvmUtil.java From Jpom with MIT License | 6 votes |
/** * 获取指定程序的线程信息 * * @param jpomTag jpomTag * @return 没有运行或者获取数据 * @throws Exception 异常 * @see ThreadMXBean */ public static ThreadMXBean getThreadMXBean(String jpomTag) throws Exception { VirtualMachine virtualMachine = JvmUtil.getVirtualMachine(jpomTag); if (virtualMachine == null) { return null; } try { JMXServiceURL url = getJMXServiceURL(virtualMachine); if (url == null) { return null; } JMXConnector jmxConnector = JMXConnectorFactory.connect(url, null); MBeanServerConnection mBeanServerConnection = jmxConnector.getMBeanServerConnection(); return ManagementFactory.newPlatformMXBeanProxy(mBeanServerConnection, ManagementFactory.THREAD_MXBEAN_NAME, ThreadMXBean.class); } finally { virtualMachine.detach(); } }
Example #13
Source File: SafeCallerImplTest.java From openhab-core with Eclipse Public License 2.0 | 6 votes |
private static String createThreadDump(String threadNamePrefix) { final StringBuilder sb = new StringBuilder(); final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); for (ThreadInfo threadInfo : threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), Integer.MAX_VALUE)) { if (!threadInfo.getThreadName().startsWith(threadNamePrefix)) { continue; } sb.append("\""); sb.append(threadInfo.getThreadName()); sb.append("\" "); sb.append(State.class.getName()); sb.append(": "); sb.append(threadInfo.getThreadState()); for (final StackTraceElement stackTraceElement : threadInfo.getStackTrace()) { sb.append("\n at "); sb.append(stackTraceElement); } } return sb.toString(); }
Example #14
Source File: JvmThreadingImpl.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * Getter for the "JvmThreadContentionMonitoring" variable. */ public EnumJvmThreadContentionMonitoring getJvmThreadContentionMonitoring() throws SnmpStatusException { ThreadMXBean mbean = getThreadMXBean(); if(!mbean.isThreadContentionMonitoringSupported()) { log.debug("getJvmThreadContentionMonitoring", "Unsupported ThreadContentionMonitoring"); return JvmThreadContentionMonitoringUnsupported; } if(mbean.isThreadContentionMonitoringEnabled()) { log.debug("getJvmThreadContentionMonitoring", "Enabled ThreadContentionMonitoring"); return JvmThreadContentionMonitoringEnabled; } else { log.debug("getJvmThreadContentionMonitoring", "Disabled ThreadContentionMonitoring"); return JvmThreadContentionMonitoringDisabled; } }
Example #15
Source File: TestThread.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * Waits until {@link TestThread} is in the certain {@link State} * and blocking on {@code object}. * * @param state The thread state * @param object The object to block on */ public void waitUntilBlockingOnObject(Thread.State state, Object object) { String want = object == null ? null : object.getClass().getName() + '@' + Integer.toHexString(System.identityHashCode(object)); ThreadMXBean tmx = ManagementFactory.getThreadMXBean(); while (isAlive()) { ThreadInfo ti = tmx.getThreadInfo(getId()); if (ti.getThreadState() == state && (want == null || want.equals(ti.getLockName()))) { return; } try { Thread.sleep(1); } catch (InterruptedException e) { } } }
Example #16
Source File: JmxSupport.java From visualvm with GNU General Public License v2.0 | 6 votes |
synchronized boolean isReadOnlyConnection() { synchronized (readOnlyConnectionLock) { if (readOnlyConnection == null) { readOnlyConnection = Boolean.FALSE; ThreadMXBean threads = getThreadBean(); if (threads != null) { try { threads.getThreadInfo(1); } catch (SecurityException ex) { readOnlyConnection = Boolean.TRUE; } } } return readOnlyConnection.booleanValue(); } }
Example #17
Source File: HangChecker.java From swift-k with Apache License 2.0 | 6 votes |
private void dumpJVMThreads(PrintStream pw) { ThreadMXBean b = ManagementFactory.getThreadMXBean(); if (b != null) { long[] ids = b.getAllThreadIds(); if (ids != null && ids.length != 0) { ThreadInfo[] tis = b.getThreadInfo(ids, true, true); pw.println("\nWaiting JVM threads:"); for (ThreadInfo ti : tis) { Thread.State state = ti.getThreadState(); if (state != Thread.State.RUNNABLE && state != Thread.State.TERMINATED) { printThreadInfo(pw, ti); } } } } }
Example #18
Source File: TestThread.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * Waits until {@link TestThread} is in the certain {@link State} * and blocking on {@code object}. * * @param state The thread state * @param object The object to block on */ public void waitUntilBlockingOnObject(Thread.State state, Object object) { String want = object == null ? null : object.getClass().getName() + '@' + Integer.toHexString(System.identityHashCode(object)); ThreadMXBean tmx = ManagementFactory.getThreadMXBean(); while (isAlive()) { ThreadInfo ti = tmx.getThreadInfo(getId()); if (ti.getThreadState() == state && (want == null || want.equals(ti.getLockName()))) { return; } try { Thread.sleep(1); } catch (InterruptedException e) { } } }
Example #19
Source File: ConnectorStopDeadlockTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
static void waitForBlock(Thread t) { Thread currentThread = Thread.currentThread(); System.out.println("waiting for thread " + t.getName() + " to block " + "on a lock held by thread " + currentThread.getName()); ThreadMXBean tm = ManagementFactory.getThreadMXBean(); while (true) { ThreadInfo ti = tm.getThreadInfo(t.getId()); if (ti == null) { System.out.println(" thread has exited"); return; } if (ti.getLockOwnerId() == currentThread.getId()) { System.out.println(" thread now blocked"); return; } Thread.yield(); } }
Example #20
Source File: ConnectorStopDeadlockTest.java From hottub with GNU General Public License v2.0 | 6 votes |
static void waitForBlock(Thread t) { Thread currentThread = Thread.currentThread(); System.out.println("waiting for thread " + t.getName() + " to block " + "on a lock held by thread " + currentThread.getName()); ThreadMXBean tm = ManagementFactory.getThreadMXBean(); while (true) { ThreadInfo ti = tm.getThreadInfo(t.getId()); if (ti == null) { System.out.println(" thread has exited"); return; } if (ti.getLockOwnerId() == currentThread.getId()) { System.out.println(" thread now blocked"); return; } Thread.yield(); } }
Example #21
Source File: ThreadMXBeanMetricFamilyCollector.java From cassandra-exporter with Apache License 2.0 | 5 votes |
public static Factory factory(final boolean perThreadTimingEnabled) { return mBean -> { if (!THREAD_MXBEAN_NAME.apply(mBean.name)) return null; return new ThreadMXBeanMetricFamilyCollector((ThreadMXBean) mBean.object, perThreadTimingEnabled); }; }
Example #22
Source File: Weaver.java From glowroot with Apache License 2.0 | 5 votes |
private void checkForDeadlockedActiveWeaving(List<Long> activeWeavingThreadIds) { ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); long[] deadlockedThreadIds = threadBean.findDeadlockedThreads(); if (deadlockedThreadIds == null || Collections.disjoint(Longs.asList(deadlockedThreadIds), activeWeavingThreadIds)) { return; } // need to disable weaving, otherwise getThreadInfo can trigger class loading and itself get // blocked by the deadlocked threads weavingDisabledForLoggingDeadlock = true; try { @Nullable ThreadInfo[] threadInfos = threadBean.getThreadInfo(deadlockedThreadIds, threadBean.isObjectMonitorUsageSupported(), false); StringBuilder sb = new StringBuilder(); for (ThreadInfo threadInfo : threadInfos) { if (threadInfo != null) { sb.append('\n'); appendThreadInfo(sb, threadInfo); } } logger.error("deadlock detected in class weaving, please report to the Glowroot" + " project:\n{}", sb); // no need to keep checking for (and logging) deadlocked active weaving throw new TerminateSubsequentExecutionsException(); } finally { weavingDisabledForLoggingDeadlock = false; } }
Example #23
Source File: JvmThreadingImpl.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Checker for the "JvmThreadContentionMonitoring" variable. */ public void checkJvmThreadContentionMonitoring( EnumJvmThreadContentionMonitoring x) throws SnmpStatusException { //Can't be set externaly to unsupported state. if(JvmThreadContentionMonitoringUnsupported.intValue()==x.intValue()) { log.debug("checkJvmThreadContentionMonitoring", "Try to set to illegal unsupported value"); throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue); } if ((JvmThreadContentionMonitoringEnabled.intValue()==x.intValue()) || (JvmThreadContentionMonitoringDisabled.intValue()==x.intValue())) { // The value is valid, but is the feature supported ? ThreadMXBean mbean = getThreadMXBean(); if(mbean.isThreadContentionMonitoringSupported()) return; log.debug("checkJvmThreadContentionMonitoring", "Unsupported operation, can't set state"); throw new SnmpStatusException(SnmpDefinitions.snmpRspInconsistentValue); } log.debug("checkJvmThreadContentionMonitoring", "Try to set to unknown value"); throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue); }
Example #24
Source File: MultiThreadedSpecTest.java From tlaplus with MIT License | 5 votes |
@Before public void setUp() { // Set the threshold before TLC (periodically) checks liveness to // the largest possible value. This essentially stops TLC from checking // liveness during model checking and delays it until the end when one // final liveness check is run. We only then get deterministic behavior // needed by this test to e.g. check the number of states generated... TLCGlobals.livenessThreshold = Double.MAX_VALUE; final ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); // Enable contention thread statistics to have the JVM measure // BlockedTime and WaitedTime. threadBean.setThreadContentionMonitoringEnabled(true); // Register a listener hot for the termination of the TLC worker // threads. // Using ThreadMXBean directly to lookup all threads after TLC has // finished has the potential that the JVM deletes the worker threads // before this test gets a chance to collect statistics. WorkerMonitor.addThreadListener(new WorkerMonitor.ThreadListener() { public synchronized void terminated(final Thread thread, final long runningTime) { final ThreadInfo threadInfo = threadBean.getThreadInfo(thread.getId()); double d = threadInfo.getBlockedTime() / (runningTime * 1.0d); double d2 = threadInfo.getWaitedTime() / (runningTime * 1.0d); performanceResults.add(new PerformanceResult(thread.getName(), d, d2)); latch.countDown(); } }); }
Example #25
Source File: ThreadingManager.java From vi with Apache License 2.0 | 5 votes |
public static Map<String,Number> getThreadStats(){ Map<String,Number> rtn = new HashMap<>(); ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); rtn.put("currentThreadCount",threadBean.getThreadCount()); rtn.put("daemonThreadCount", threadBean.getDaemonThreadCount()); rtn.put("totalStartedThreadCount", threadBean.getTotalStartedThreadCount()); rtn.put("peakThreadCount", threadBean.getPeakThreadCount()); return rtn; }
Example #26
Source File: JmxSupport.java From visualvm with GNU General Public License v2.0 | 5 votes |
private void printThreads(final StringBuilder sb, final ThreadMXBean threadMXBean, ThreadInfo[] threads) { boolean jdk16 = hasDumpAllThreads(); for (ThreadInfo thread : threads) { if (thread != null) { if (jdk16) { print16Thread(sb, threadMXBean, thread); } else { print15Thread(sb, thread); } } } }
Example #27
Source File: InvalidThreadID.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String argv[]) { ThreadMXBean mbean = ManagementFactory.getThreadMXBean(); int cnt = 0; long [] idArr = {0, -1, -2, (Long.MIN_VALUE + 1), Long.MIN_VALUE}; if (mbean.isThreadCpuTimeSupported()) { for (int i = 0; i < idArr.length; i++) { try { mbean.getThreadCpuTime(idArr[i]); System.out.println("Test failed. IllegalArgumentException" + " expected for ID = " + idArr[i]); } catch (IllegalArgumentException iae) { cnt++; } } if (cnt != idArr.length) { throw new RuntimeException("Unexpected number of " + "IllegalArgumentException = " + cnt + " expected = " + idArr.length); } // CPU time for a non-existence thread long time = mbean.getThreadCpuTime(999999); if (time < 0 && time != -1) { throw new RuntimeException("Cpu time for thread 999999" + " is invalid = " + time + " expected to be -1."); } } System.out.println("Test passed."); }
Example #28
Source File: TestThread.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Waits until {@link TestThread} is in native. */ public void waitUntilInNative() { ThreadMXBean tmx = ManagementFactory.getThreadMXBean(); while (isAlive()) { ThreadInfo ti = tmx.getThreadInfo(getId()); if (ti.isInNative()) { return; } try { Thread.sleep(1); } catch (InterruptedException e) { } } }
Example #29
Source File: JvmThreadingImpl.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
/** * Setter for the "JvmThreadCpuTimeMonitoring" variable. */ public void setJvmThreadCpuTimeMonitoring(EnumJvmThreadCpuTimeMonitoring x) throws SnmpStatusException { ThreadMXBean mbean = getThreadMXBean(); // We can trust the received value, it has been checked in // checkJvmThreadCpuTimeMonitoring if(JvmThreadCpuTimeMonitoringEnabled.intValue() == x.intValue()) mbean.setThreadCpuTimeEnabled(true); else mbean.setThreadCpuTimeEnabled(false); }
Example #30
Source File: JvmThreadingImpl.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Checker for the "JvmThreadCpuTimeMonitoring" variable. */ public void checkJvmThreadCpuTimeMonitoring(EnumJvmThreadCpuTimeMonitoring x) throws SnmpStatusException { //Can't be set externaly to unsupported state. if(JvmThreadCpuTimeMonitoringUnsupported.intValue() == x.intValue()) { log.debug("checkJvmThreadCpuTimeMonitoring", "Try to set to illegal unsupported value"); throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue); } if ((JvmThreadCpuTimeMonitoringEnabled.intValue() == x.intValue()) || (JvmThreadCpuTimeMonitoringDisabled.intValue() == x.intValue())) { // The value is a valid value. But is the feature supported? ThreadMXBean mbean = getThreadMXBean(); if(mbean.isThreadCpuTimeSupported()) return; // Not supported. log.debug("checkJvmThreadCpuTimeMonitoring", "Unsupported operation, can't set state"); throw new SnmpStatusException(SnmpDefinitions.snmpRspInconsistentValue); } // Unknown value. log.debug("checkJvmThreadCpuTimeMonitoring", "unknown enum value "); throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue); }