Exemple #1
0
            public bool Get()
            {
                ThreadMXBean threadBean = ManagementFactory.GetThreadMXBean();

                ThreadInfo[] threads = threadBean.GetThreadInfo(threadBean.GetAllThreadIds(), 1);
                foreach (ThreadInfo thread in threads)
                {
                    if (thread.GetThreadName().StartsWith("TransferFsImageUpload"))
                    {
                        return(false);
                    }
                }
                return(true);
            }
            public virtual void Run()
            {
                long startTime = ManagementFactory.GetThreadMXBean().GetThreadCpuTime(jvmThreadId);

                foreach (T datum in queue)
                {
                    localLogLikelihood += fn.GetSummaryForInstance(datum, weights, localDerivative);
                    // Check for user interrupt
                    if (mainWorker.isFinished)
                    {
                        return;
                    }
                }
                finishedAtTime = Runtime.CurrentTimeMillis();
                long endTime = ManagementFactory.GetThreadMXBean().GetThreadCpuTime(jvmThreadId);

                cpuTimeRequired = endTime - startTime;
            }
        /// <summary>
        /// Assert that there are no threads running whose name matches the
        /// given regular expression.
        /// </summary>
        /// <param name="regex">the regex to match against</param>
        public static void AssertNoThreadsMatching(string regex)
        {
            Pattern      pattern    = Pattern.Compile(regex);
            ThreadMXBean threadBean = ManagementFactory.GetThreadMXBean();

            ThreadInfo[] infos = threadBean.GetThreadInfo(threadBean.GetAllThreadIds(), 20);
            foreach (ThreadInfo info in infos)
            {
                if (info == null)
                {
                    continue;
                }
                if (pattern.Matcher(info.GetThreadName()).Matches())
                {
                    NUnit.Framework.Assert.Fail("Leaked thread: " + info + "\n" + Joiner.On("\n").Join
                                                    (info.GetStackTrace()));
                }
            }
        }
Exemple #4
0
        private static int CountTimerThreads()
        {
            ThreadMXBean threadBean = ManagementFactory.GetThreadMXBean();
            int          count      = 0;

            ThreadInfo[] infos = threadBean.GetThreadInfo(threadBean.GetAllThreadIds(), 20);
            foreach (ThreadInfo info in infos)
            {
                if (info == null)
                {
                    continue;
                }
                foreach (StackTraceElement elem in info.GetStackTrace())
                {
                    if (elem.GetClassName().Contains("Timer"))
                    {
                        count++;
                        break;
                    }
                }
            }
            return(count);
        }
        internal static string BuildDeadlockInfo()
        {
            ThreadMXBean threadBean = ManagementFactory.GetThreadMXBean();

            long[] threadIds = threadBean.FindMonitorDeadlockedThreads();
            if (threadIds != null && threadIds.Length > 0)
            {
                StringWriter stringWriter = new StringWriter();
                PrintWriter  @out         = new PrintWriter(stringWriter);
                ThreadInfo[] infos        = threadBean.GetThreadInfo(threadIds, true, true);
                foreach (ThreadInfo ti in infos)
                {
                    PrintThreadInfo(ti, @out);
                    PrintLockInfo(ti.GetLockedSynchronizers(), @out);
                    @out.WriteLine();
                }
                @out.Close();
                return(stringWriter.ToString());
            }
            else
            {
                return(null);
            }
        }
Exemple #6
0
        private void DoThreadUpdates()
        {
            ThreadMXBean threadMXBean = ManagementFactory.GetThreadMXBean();

            long[]       threadIds           = threadMXBean.GetAllThreadIds();
            ThreadInfo[] threadInfos         = threadMXBean.GetThreadInfo(threadIds, 0);
            int          threadsNew          = 0;
            int          threadsRunnable     = 0;
            int          threadsBlocked      = 0;
            int          threadsWaiting      = 0;
            int          threadsTimedWaiting = 0;
            int          threadsTerminated   = 0;

            foreach (ThreadInfo threadInfo in threadInfos)
            {
                // threadInfo is null if the thread is not alive or doesn't exist
                if (threadInfo == null)
                {
                    continue;
                }
                Thread.State state = threadInfo.GetThreadState();
                if (state == Thread.State.New)
                {
                    threadsNew++;
                }
                else
                {
                    if (state == Thread.State.Runnable)
                    {
                        threadsRunnable++;
                    }
                    else
                    {
                        if (state == Thread.State.Blocked)
                        {
                            threadsBlocked++;
                        }
                        else
                        {
                            if (state == Thread.State.Waiting)
                            {
                                threadsWaiting++;
                            }
                            else
                            {
                                if (state == Thread.State.TimedWaiting)
                                {
                                    threadsTimedWaiting++;
                                }
                                else
                                {
                                    if (state == Thread.State.Terminated)
                                    {
                                        threadsTerminated++;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            metrics.SetMetric("threadsNew", threadsNew);
            metrics.SetMetric("threadsRunnable", threadsRunnable);
            metrics.SetMetric("threadsBlocked", threadsBlocked);
            metrics.SetMetric("threadsWaiting", threadsWaiting);
            metrics.SetMetric("threadsTimedWaiting", threadsTimedWaiting);
            metrics.SetMetric("threadsTerminated", threadsTerminated);
        }