了解java.lang.Thread.State:WAITING(停车) [英] Understanding java.lang.Thread.State: WAITING (parking)

查看:4795
本文介绍了了解java.lang.Thread.State:WAITING(停车)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,一个非常愚蠢的问题,我只是想知道等待'停车'是什么意思?线程是等待停放还是刚停放,因此处于等待状态?当停车发生时,需要多少CPU /内存资源?停放线程的目的是什么?

First, a really dumb question, I was just wondering what the waiting 'parking' means ? Is the thread waiting to be parked or is it just been parked and therefore is in wait state ? And when that parking happen, how much cpu/memory resources are taken ? What's the purpose of parking a thread ?

其次,通过查看 java thread API

除非许可证可用,否则禁用当前线程以进行线程调度。

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

如果许可证可用,那么它将被消耗,并且呼叫立即返回;否则当前线程因线程调度而被禁用,并且在三种情况之一发生之前​​处于休眠状态.....

If the permit is available then it is consumed and the call returns immediately; otherwise the current thread becomes disabled for thread scheduling purposes and lies dormant until one of three things happens.....

英语不是我的主要语言,所以我很难理解,我打算'允许'作为允许停放线程,所以接下来的问题:

English is not my primary language, so I have some difficulties understanding that, I intended 'permit' as kind of 'permission to park the thread', so the questions that follow:


  • 这是什么意思,什么是许可,以及检查这些许可的人和方式是什么?

  • 这是什么意思:'如果有许可证,那么它是消耗',它是否'停止'?

  • 跟随,如果第二点是真的,那么'停车'和'休眠'之间有什么区别?如果我有许可证我可以永久停放,如果没有,我可以让它休眠吗?

谢谢

推荐答案

许可证表示继续执行的权限。停车意味着暂停执行直到获得许可。

Permit means a permission to continue execution. Parking means suspending execution until permit is available.

信号量 的许可证, LockSupport 的许可证与线程(即允许给予特定线程)并且不会累积(即每个线程只能有一个许可证,当线程消耗许可证时,它会消失)。

Unlike Semaphore's permits, 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).

您可以通过调用 unpark()为线程提供许可。线程可以通过调用 park()来暂停其执行,直到permit可用(或线程被中断,或超时到期等)。当许可证可用时,停放的线程使用它并退出 park()方法。

You can give permit to a thread by calling unpark(). A thread can suspend its execution until permit is available (or thread is interrupted, or timeout expired, etc) by calling park(). When permit is available, the parked thread consumes it and exits a park() method.

这篇关于了解java.lang.Thread.State:WAITING(停车)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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