VisualVM - 线程状态 [英] VisualVM - Thread States

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

问题描述

有人可以解释一下睡觉等待 Park 监视 VisualVM中的线程状态。

Can someone please explain me the difference between Sleeping, Wait, Park, and Monitor thread states in VisualVM.

这是我发现的:

正在运行:线程仍在运行。

睡眠:线程正在休眠(在线程对象上调用方法yield())

等待:线程被互斥锁或屏障阻塞,正在等待另一个线程释放锁定

Park :暂停线程暂停,直到获得许可。取消停放线程通常是通过在线程对象上调用方法unpark()来完成的。

监控:线程正在等待条件变为真,以便恢复执行

Running: thread is still running.
Sleeping: thread is sleeping (method yield() was called on the thread object)
Wait: thread was blocked by a mutex or a barrier, and is waiting for another thread to release the lock
Park: parked threads are suspended until they are given a permit. Unparking a thread is usually done by calling method unpark() on the thread object
Monitor: threads are waiting on a condition to become true to resume execution

我无法理解的是州立公园,实际上是什么暂停线程?如何在代码中检测到线程暂停执行的原因?

What I am unable to understand is the state Park, what actually suspends the thread? How do I detect in the code what has made the thread suspend its execution?

有人可以指导我这方面。

Can someone please guide me in this regard.

谢谢。

推荐答案

我使用谷歌,出现的第一页有一个非常好的图表几乎描述了你需要/想知道的一切。下次值得尝试谷歌这些类型的问题。

I have used google and the very first page that came up had a very nice diagram which pretty much describes all you need/want to know. Next time its worth trying google for these type of questions.

1)新

如果创建Thread类的实例但在调用start()之前,线程处于新状态方法。

The thread is in new state if you create an instance of Thread class but before the invocation of start() method.

2)Runnable

2) Runnable

调用start()方法后线程处于runnable状态,但是线程调度程序尚未选择它作为正在运行的线程。

The thread is in runnable state after invocation of start() method, but the thread scheduler has not selected it to be the running thread.

3)正在运行

线程在如果线程调度程序已选择它,则运行状态。

The thread is in running state if the thread scheduler has selected it.

4)等待时间

定时等待是线程状态对于等待指定等待时间的线程。由于在指定的正等待时间内调用以下方法之一,线程处于定时等待状态:

Timed waiting is a thread state for a thread waiting with a specified waiting time. A thread is in the timed waiting state due to calling one of the following methods with a specified positive waiting time:


  • Thread.sleep(sleeptime) )

  • Object.wait(超时)

  • Thread.join(超时)

  • LockSupport.parkNanos(超时)

  • LockSupport.parkUntil(超时)

  • Thread.sleep(sleeptime)
  • Object.wait(timeout)
  • Thread.join(timeout)
  • LockSupport.parkNanos(timeout)
  • LockSupport.parkUntil(timeout)

5)非可运行(已阻止)

5) Non-Runnable (Blocked)

这是线程仍处于活动状态但当前没有资格运行的状态。

This is the state when the thread is still alive, but is currently not eligible to run.

6 )终止

当run()方法退出时,线程处于终止或死状态。

A thread is in terminated or dead state when its run() method exits.

希望这个回答你的问题:)。

Hopefully this answers your question :).

停车:


禁用当前线程用于线程调度目的,除非
许可证可用。

Disables the current thread for thread scheduling purposes unless the permit is available.

如果您想将此线程称为此线程,则线程正在停止或暂停因为它没有执行权限。授予权限后,线程将被取消并执行。

Threads are being parked or suspended if you like to call it this way because it does not have a permission to execute. Once permission is granted the thread will be unparked and execute.

LockSupport的许可与线程相关联(即许可被赋予特定的线程)并且不会累积(即线程时每个线程只能有一个许可)消耗许可证,它消失了。

Permits of LockSupport are associated with threads (i.e. permit is given to a particular thread) and doesn't accumulate (i.e. there can be only one permit per thread, when thread consumes the permit, it disappears).

这篇关于VisualVM - 线程状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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