You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Out of curiosity, what is gained by initializing RateLimiter.mutex() lazily? Effective Java Item 71 ("Use lazy initialization judiciously") strongly recommends against lazy initialization unless the object being initialized is expensive to construct. This is certainly not the case for you.
Consider:
All RateLimiter's public methods require the use of mutex.
Removing lazy initialization would simplify the code.
Performance might improve slightly as you no longer need to check if mutex is null over and over again.
The text was updated successfully, but these errors were encountered:
Yep. Inline field initialization is syntactic sugar for initializing from
the constructor. Feel free to give it a shot; the tests should catch the
problem, and you can peek at the bytecode with javap.
Out of curiosity, what is gained by initializing
RateLimiter.mutex()
lazily? Effective Java Item 71 ("Use lazy initialization judiciously") strongly recommends against lazy initialization unless the object being initialized is expensive to construct. This is certainly not the case for you.Consider:
RateLimiter
's public methods require the use ofmutex
.mutex
is null over and over again.The text was updated successfully, but these errors were encountered: