How java threads are scheduled?

前端 未结 4 2108
后悔当初
后悔当初 2021-01-06 09:00

I have recently started multi-threaded programming with Java in case of Linux threads , i know that the kernel schedules them(as they are the unit entities that are schedule

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-06 09:32

    Threads in the java/JVM process maps to a native thread and you can see both the java thread id and the native thread id in a thread stack trace dump. Get the thread stack of all java threads using your favorite tool:

    • command line signal like ctrl+break (windows) or ctrl+\ linux) in the console where the java program is running
    • command line tool (kill -QUIT or jstack from the jdk)
    • visual vm in the jdk and/or jmx etc

    Example extract from the first line of such a thread dump: ... tid=0x0000002adaba9c00 nid=0x754c ...

    • tid = java thread id

    • nid = native id (the OS thread id)

    Use the operating system's tools to find out more about the thread using the native id (it is in hex).

    Inside the java code you have ThreadMXBean to retrieve more thread information programatically if you want http://docs.oracle.com/javase/6/docs/api/java/lang/management/ThreadMXBean.html

提交回复
热议问题