Java:等待同步块,谁先走? [英] Java: waiting on synchronized block, who goes first?

查看:113
本文介绍了Java:等待同步块,谁先走?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题的灵感来自此其他问题

如果多个线程在 synchronized 块上等待,并且锁定变为可用,谁先行?是通过线程优先级(先到先服务)吗?

If multiple threads are waiting on a synchronized block, and the lock becomes available, who goes first? Is it by thread priority (and then first-come-first-served)?

并且相同的规则适用于通知(多个等待线程)?

And do the same rules apply for notify (with multiple waiting threads)?

推荐答案

根据对这个家伙: http://tutorials.jenkov.com/java-concurrency /starvation-and-fairness.html

Java不对序列发出任何保证。所以我猜它不是基于线程优先级

Java issues no guarantees about the sequence. So I guess it is not based on thread priority

我将尝试进一步了解Java如何确定谁先行。

I'll try to look further for an explanation on how Java actually decides who goes first.

这篇关于Java:等待同步块,谁先走?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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