开发者

Synchronized Adventure

开发者 https://www.devze.com 2023-03-05 03:21 出处:网络
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 pe

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

精彩评论

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