开发者

Synchronized Adventure

If i come across a situation where i will have to make each and every method in my Java program synchronized, will that affect the performance of my co开发者_如何学运维de?


Yes, it will influence the performance.

If your application is mostly single-threaded, then the impact will be very small, because uncontested lock acquisition is very fast (on modern JVMs such as HotSpot).

If your application is heavily multi-threaded and multiple threads access the same objects concurrently, then the impact will be larger.

Note that having every single method synchronized does not guarantee that your code is thread-safe, you can still easily get race conditions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜