java并发性是指什么_java – 什么是“非阻塞”并发,它与普通并发性有什么不同?...
What is Non-blocking Concurrency and
how is it different.
正式:
In computer science, non-blocking
synchronization ensures that threads
competing for a shared resource do not
have their execution indefinitely
postponed by mutual exclusion. A
non-blocking algorithm is lock-free if
there is guaranteed system-wide
progress; wait-free if there is also
guaranteed per-thread progress.
(wikipedia)
非正式:非阻塞與阻塞的最有利的特征之一是線程不必被操作系統掛起/喚醒。這樣的開銷可以達到1ms到幾十ms,所以刪除這個可能是一個很大的性能增益。在java中,這也意味著您可以選擇使用非公平的鎖定,這可以比公平鎖定具有更多的系統吞吐量。
I have heard that this is available
in Java. Are there any particular
scenarios we should use this feature
是的,來自Java5。實際上,在Java中,您應該基本上盡可能地嘗試使用java.util.concurrent滿足您的需求(這在很多情況下都會使用非阻塞并發性,但是在大多數情況下您不必明確擔心)。只有在沒有其他選項的情況下,應該使用同步包裝器(.synchronizedList()等)或手動同步關鍵字。這樣一來,大部分時間都可以使用更可維護,更好的應用程序。
當有很多爭用時,非阻塞并發特別有利。當您需要阻止(公平鎖定,事件驅動的東西,最大長度等等)等等時,您不能使用它,但是如果不需要它,則在大多數情況下,非阻塞并發往往更好。
Is there a difference/advantage of
using one of these methods for a
collection. What are the trade offs
兩者都有相同的行為(字節碼應該相等)。但是我建議使用Collections.synchronized,因為它更短=更小的空間擰緊!
總結
以上是生活随笔為你收集整理的java并发性是指什么_java – 什么是“非阻塞”并发,它与普通并发性有什么不同?...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jq步骤条 java_JQuery实现步
- 下一篇: ajax请求php保存数据格式,jQue