خرید بک لینک

Vote count: 0

I love the @Synchronized aotation that Groovy provides. It is a safer option than the 'synchronized' keyword for Java since it uses a local / private lock variable rather than the 'this' object. However in Groovy all rules can be broken. :)

I also know there is Lombok, a Java library that provides the same feature.

But is there a way to use an aotation within a method so that some of the method's code is not synchronized (for better performance) and other parts are (out of necessity)?

While I was typing this question I may have come up with one solution to my own question:

  • Extract method: create a new method, move the block of code that needs synchronization into that method. The original code calls the new method. New method has @Synchronized.

Does that sound right? Any better ideas?

asked 37 secs ago

برچسب: نویسنده: استخدام کار تاريخ: شنبه 14 فروردين 1395 ساعت: 0:58

صفحه بندی