-
Notifications
You must be signed in to change notification settings - Fork 784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2019-07-17:说一下线程的几种状态? #99
Comments
new |
第一是创建状态。在生成线程对象,并没有调用该对象的start方法,这是线程处于创建状态。 |
1.初始(NEW) ,创建线程对象 具体参考:线程状态及切换 |
|
网上大多说五种,但也有六种的说法,萌新表示很迷惑啊大佬们 |
线程的状态 当new Thread新建线程时 线程为NEW 新建状态 进入就绪状态的线程 会等待CPU分配时间片 之后进入运行状态 执行任务 如果线程在运行中被调用了sleep睡眠 中断join(放弃CPU占用而停止运行的情况)都会进入阻塞状态加入到阻塞队列中 等待唤醒或者时间到 执行完毕后进入死亡状态 |
到底有多少种状态?看下
|
java中比较容易混淆的几个api
|
6种是操作系统的分类和java的分发略有不同 |
new |
感觉 stackoverflow 上这个人解释的 blcoked 和waiting的区别比较清楚 A thread goes to wait state once it calls wait() on an Object. This is called Waiting State. Once a thread reaches waiting state, it will need to wait till some other thread calls notify() or notifyAll() on the object. Once this thread is notified, it will not be runnable. It might be that other threads are also notified (using notifyAll()) or the first thread has not finished his work, so it is still blocked till it gets its chance. This is called Blocked State. A Blocked state will occur whenever a thread tries to acquire lock on object and some other thread is already holding the lock. Once other threads have left and its this thread chance, it moves to Runnable state after that it is eligible pick up work based on JVM threading mechanism and moves to run state. |
这是来自QQ邮箱的假期自动回复邮件。
|
这是来自QQ邮箱的假期自动回复邮件。
您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。
|
No description provided.
The text was updated successfully, but these errors were encountered: