getState() public method

public getState ( ) : global::java.lang.Thread.State
return global::java.lang.Thread.State
Ejemplo n.º 1
0
 private static void DumpAllJavaThreads()
 {
     Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
     java.util.Map traces = java.lang.Thread.getAllStackTraces();
     Console.WriteLine("Full thread dump IKVM.NET {0} ({1} bit):", JVM.SafeGetAssemblyVersion(Assembly.GetExecutingAssembly()), IntPtr.Size * 8);
     java.util.Iterator entries = traces.entrySet().iterator();
     while (entries.hasNext())
     {
         java.util.Map.Entry entry  = (java.util.Map.Entry)entries.next();
         java.lang.Thread    thread = (java.lang.Thread)entry.getKey();
         Console.WriteLine("\n\"{0}\"{1} prio={2} tid=0x{3:X8}", thread.getName(), thread.isDaemon() ? " daemon" : "", thread.getPriority(), thread.getId());
         Console.WriteLine("   java.lang.Thread.State: " + thread.getState());
         java.lang.StackTraceElement[] trace = (java.lang.StackTraceElement[])entry.getValue();
         for (int i = 0; i < trace.Length; i++)
         {
             Console.WriteLine("\tat {0}", trace[i]);
         }
     }
     Console.WriteLine();
 }
Ejemplo n.º 2
0
    public static void getThreadInfo1(long[] ids, int maxDepth, object result)
    {
#if !FIRST_PASS
        System.Reflection.ConstructorInfo[] constructors = typeof(java.lang.management.ThreadInfo).GetConstructors(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
        foreach (System.Reflection.ConstructorInfo constructor in constructors)
        {
            if (constructor.GetParameters().Length == 9)
            {
                java.lang.Thread[] threads = (java.lang.Thread[])getThreads();
                java.lang.management.ThreadInfo[] threadInfos = (java.lang.management.ThreadInfo[])result;
                for (int i = 0; i < ids.Length; i++)
                {
                    long id = ids[i];
                    for (int t = 0; t < threads.Length; t++)
                    {
                        if (threads[t].getId() == id)
                        {
                            java.lang.Thread thread = threads[t];

                            int state;
                            // invers to sun.misc.VM.toThreadState
                            switch (thread.getState().ordinal())
                            {
                            case (int)java.lang.Thread.State.__Enum.RUNNABLE:
                                state = JVMTI_THREAD_STATE_RUNNABLE;
                                break;

                            case (int)java.lang.Thread.State.__Enum.BLOCKED:
                                state = JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER;
                                break;

                            case (int)java.lang.Thread.State.__Enum.WAITING:
                                state = JVMTI_THREAD_STATE_WAITING_INDEFINITELY;
                                break;

                            case (int)java.lang.Thread.State.__Enum.TIMED_WAITING:
                                state = JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT;
                                break;

                            case (int)java.lang.Thread.State.__Enum.TERMINATED:
                                state = JVMTI_THREAD_STATE_TERMINATED;
                                break;

                            case (int)java.lang.Thread.State.__Enum.NEW:
                                state = JVMTI_THREAD_STATE_ALIVE;
                                break;

                            default:
                                state = 0;
                                break;
                            }
                            //TODO set in state JMM_THREAD_STATE_FLAG_SUSPENDED if the thread is suspended

                            java.lang.StackTraceElement[] stacktrace = thread.getStackTrace();
                            if (maxDepth >= 0 && maxDepth < stacktrace.Length)
                            {
                                java.lang.StackTraceElement[] temp = new java.lang.StackTraceElement[maxDepth];
                                System.Array.Copy(stacktrace, temp, temp.Length);
                                stacktrace = temp;
                            }

                            object[] parameters = new object[9];
                            parameters[0] = thread;                     // thread
                            parameters[1] = state;                      // state
                                                                        // lockObj
                                                                        // lockOwner
                            parameters[4]  = 0;                         // blockedCount
                            parameters[5]  = 0;                         // blockedTime
                            parameters[6]  = -1;                        // waitedCount
                            parameters[7]  = 0;                         // waitedTime
                            parameters[8]  = stacktrace;                // stackTrace
                            threadInfos[i] = (java.lang.management.ThreadInfo)constructor.Invoke(parameters);
                            break;
                        }
                    }
                }
                return;
            }
        }
        throw new java.lang.InternalError("Constructor for java.lang.management.ThreadInfo not find.");
#endif
    }