如何安排java线程? [英] How java threads are scheduled?

查看:158
本文介绍了如何安排java线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在Linux线程的情况下使用Java
开始多线程编程,我知道内核会调度它们(因为它们是被调度的单元实体)但是java程序在JVM上运行我的系统(RHEL 6.1)是作为一个作为用户空间实例运行的程序实现的。因此,如果没有内核知道java线程,那么如何在JVM中完成抢占式多任务处理?如果给出JVM和内核交互的整个机制,那将会很有帮助。

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 scheduled)but java programs are run on JVM which in my system (RHEL 6.1) is implemented as a program that is run as a user space instance .So, without the kernel being aware of the java threads, how come preemptive multitasking is done in JVM? it will be helpful if the whole mechanism of JVM and kernel interaction in doing this thing is given.

请引用可能的信息来源

推荐答案

java中的主题/ JVM进程映射到本机线程,您可以在线程堆栈跟踪转储中看到java线程标识和本机线程标识。使用您最喜欢的工具获取所有Java线程的线程堆栈:

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:


  • 命令行信号如ctrl + break(windows)或ctrl + \ linux )在运行java程序的控制台中

  • 命令行工具(从jdk中杀死-QUIT或jstack)

  • jdk中的visual vm和/或jmx等

此类线程转储第一行的示例摘录:
... tid = 0x0000002adaba9c00 nid = 0x754c ...

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


  • tid = java thread id

  • tid = java thread id

nid =本机ID(操作系统线程ID)

nid = native id (the OS thread id)

使用操作系统的工具了解更多信息关于使用本机id的线程(它是十六进制)。

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

在java代码中你有ThreadMXBean以编程方式检索更多线程信息,如果你想要
< a href =http://docs.oracle.com/javase/6/docs/api/java/lang/management/ThreadMXBean.html =nofollow> http://docs.oracle.com/javase/ 6 /文档/ API / JAV a / lang / management / ThreadMXBean.html

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

这篇关于如何安排java线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆