Example usage for java.lang.management ManagementFactory getThreadMXBean

List of usage examples for java.lang.management ManagementFactory getThreadMXBean

Introduction

In this page you can find the example usage for java.lang.management ManagementFactory getThreadMXBean.

Prototype

public static ThreadMXBean getThreadMXBean() 

Source Link

Document

Returns the managed bean for the thread system of the Java virtual machine.

Usage

From source file:hudson.Functions.java

@IgnoreJRERequirement
public static ThreadInfo[] getThreadInfos() {
    ThreadMXBean mbean = ManagementFactory.getThreadMXBean();
    return mbean.getThreadInfo(mbean.getAllThreadIds(), mbean.isObjectMonitorUsageSupported(),
            mbean.isSynchronizerUsageSupported());
}

From source file:org.unitime.timetable.onlinesectioning.OnlineSectioningHelper.java

public static long getCpuTime() {
    return ManagementFactory.getThreadMXBean().isCurrentThreadCpuTimeSupported()
            ? ManagementFactory.getThreadMXBean().getCurrentThreadCpuTime()
            : 1000000l * System.currentTimeMillis();
}

From source file:jtabwb.launcher.Launcher.java

private void searchProof(ProofSearchData proofSearchData) {
    // BUILD THE ENGINE
    //currentConfiguration.engineExecutionMode = ExecutionMode.ENGINE_VERBOSE;
    Engine engine = new Engine(proofSearchData.selectedProver, proofSearchData.goal,
            currentConfiguration.engineExecutionMode);

    if (!currentConfiguration.testsetmode)
        LOG.info(MSG.LAUNCHER.INFO.PROVING_BEGIN);

    // start the proof search
    ThreadMXBean bean = ManagementFactory.getThreadMXBean();
    proofSearchData.execution_start_time = getCurrentTimeMilleseconds();
    long cpuTime = bean.getCurrentThreadCpuTime();
    engine.searchProof();//  w ww.  j a  v a2s.  c  o m
    // end of proof search, set info values
    cpuTime = bean.getCurrentThreadCpuTime() - cpuTime;
    proofSearchData.execution_end_time = getCurrentTimeMilleseconds();

    // set the data of the last proof search
    IterationInfo lastIterationInfo = engine.getLastIterationInfo();
    proofSearchData.proofSearchResult = engine.getResult();
    proofSearchData.testStatus = TestStatus.getTestStatus(proofSearchData);
    proofSearchData.iterationCounter = lastIterationInfo.getNumberOfIterations();
    proofSearchData.max_stack_size = lastIterationInfo.getMaxStackSize();
    proofSearchData.proofSearchResult = engine.getResult();
    proofSearchData.numberOfRestoredBacktrackPoints = lastIterationInfo.getNumberOfRestoredBacktrackPoints();
    proofSearchData.numberOfGeneratedNodes = lastIterationInfo.getNumberOfGeneratedNodes();
    proofSearchData.numberOfRestoredBranchPoints = lastIterationInfo.getNumberOfRestoredBranchPoints();

    // generates data and data files according with defined options 
    if (currentConfiguration.engineExecutionMode == ExecutionMode.ENGINE_TRACE)
        proofSearchData.trace = engine.getTrace();

    if (currentConfiguration.testsetmode)
        testset_printSingleTestInfo(proofSearchData);
    else {
        print_postProofSearchDetails(proofSearchData);

        if (currentConfiguration.generateLogFile)
            log_generateFile(proofSearchData);

        if (currentConfiguration.generateLogTimeFile)
            timeLog_generateFile(proofSearchData);

        if (currentConfiguration.generateLatexOfProof)
            latexProof_generateFile(proofSearchData);

        if (currentConfiguration.generateLatexOfCtrees)
            latexCtrees_generateFile(proofSearchData);

        if (currentConfiguration.saveTrace)
            trace_generateFile(proofSearchData);

        if (currentConfiguration.generatef3TimeStr)
            timing_f3time_generateString(proofSearchData);

        if (currentConfiguration.generateJTabWbTimeStr)
            timing_jtabwb_generatesString(proofSearchData);
    }

}

From source file:org.apache.storm.utils.Utils.java

/**
 * Gets some information, including stack trace, for a running thread.
 * @return A human-readable string of the dump.
 *///from  w w  w .j  a  v a 2 s .c  o m
public static String threadDump() {
    final StringBuilder dump = new StringBuilder();
    final java.lang.management.ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
    final java.lang.management.ThreadInfo[] threadInfos = threadMXBean
            .getThreadInfo(threadMXBean.getAllThreadIds(), 100);
    for (java.lang.management.ThreadInfo threadInfo : threadInfos) {
        dump.append('"');
        dump.append(threadInfo.getThreadName());
        dump.append("\" ");
        dump.append("\n   lock: ");
        dump.append(threadInfo.getLockName());
        dump.append(" owner: ");
        dump.append(threadInfo.getLockOwnerName());
        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");
    }
    return dump.toString();
}

From source file:com.eurelis.opencms.admin.systeminformation.CmsDBPoolsOverviewDialog.java

/**
 * Initializes the infos object.<p>
 *//*from  w w  w  .  j  av a  2s  . c  o  m*/
protected void initInfosObject() {

    com.sun.management.OperatingSystemMXBean sunOsBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory
            .getOperatingSystemMXBean();
    java.lang.management.OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
    java.lang.management.ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    java.lang.management.RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
    java.lang.management.ClassLoadingMXBean classesBean = ManagementFactory.getClassLoadingMXBean();

    initPools();

    Object o;
    if (CmsStringUtil.isEmpty(getParamAction())) {
        o = new CmsAdminSettings(getSession());
    } else {
        // this is not the initial call, get the job object from session
        o = getDialogObject();
    }
    if (!(o instanceof CmsAdminSettings)) {
        // create a new history settings handler object
        m_adminSettings = new CmsAdminSettings(getSession());
    } else {
        // reuse html import handler object stored in session
        m_adminSettings = (CmsAdminSettings) o;
    }

    setParamCloseLink(getJsp().link(
            "/system/workplace/views/admin/admin-main.jsp?path=/eurelis_system_information/database_pools.jsp"));

}

From source file:org.apache.tez.runtime.LogicalIOProcessorRuntimeTask.java

/**
 * Print all threads in JVM (only for debugging)
 *///w w w .ja  v  a 2  s  .c  o  m
void printThreads() {
    //Print the status of all threads in JVM
    ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
    long[] threadIds = threadMXBean.getAllThreadIds();
    for (Long id : threadIds) {
        ThreadInfo threadInfo = threadMXBean.getThreadInfo(id);
        // The thread could have been shutdown before we read info about it.
        if (threadInfo != null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("ThreadId : " + id + ", name=" + threadInfo.getThreadName());
            }
        }
    }
}

From source file:com.google.dart.tools.core.DartCore.java

@Override
public void start(BundleContext context) throws Exception {
    super.start(context);

    CmdLineOptions.setOptions(CmdLineOptions.parseCmdLine(Platform.getApplicationArgs()));
    CmdLineOptions.getOptions().printWarnings();

    if (DartCoreDebug.PERF_THREAD_CONTENTION_MONIOR) {
        try {/* w w w. ja  v a 2  s  .c  o  m*/
            java.lang.management.ThreadMXBean th = ManagementFactory.getThreadMXBean();
            th.setThreadContentionMonitoringEnabled(true);
        } catch (UnsupportedOperationException e) {
        }
    }

    AnalysisEngine analysisEngine = AnalysisEngine.getInstance();
    analysisEngine.setLogger(new Logger() {
        @Override
        public void logError(String message) {
            DartCore.logError(message);
        }

        @Override
        public void logError(String message, Throwable exception) {
            DartCore.logError(message, exception);
        }

        @Override
        public void logInformation(String message) {
            DartCore.logInformation(message);
        }

        @Override
        public void logInformation(String message, Throwable exception) {
            DartCore.logInformation(message, exception);
        }
    });
    Logging.setLogger(new com.google.dart.server.utilities.logging.Logger() {
        @Override
        public void logError(String message) {
            DartCore.logError(message);
        }

        @Override
        public void logError(String message, Throwable exception) {
            DartCore.logError(message, exception);
        }

        @Override
        public void logInformation(String message) {
            DartCore.logInformation(message);
        }

        @Override
        public void logInformation(String message, Throwable exception) {
            DartCore.logInformation(message, exception);
        }
    });

    DartSdkManager.getManager().addSdkListener(this);
    if (!DartCoreDebug.ENABLE_ANALYSIS_SERVER) {
        getProjectManager().hookListeners();
    } else {
        getAnalysisServer();
    }
}

From source file:org.apache.hadoop.mapred.JobTracker.java

@Override
public int getThreadCount() {
    return ManagementFactory.getThreadMXBean().getThreadCount();
}

From source file:org.apache.hadoop.hdfs.server.namenode.FSNamesystem.java

@Override // NameNodeMXBean
public int getThreads() {
    return ManagementFactory.getThreadMXBean().getThreadCount();
}