Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider initializing RateLimiter.mutex eagerly #3066

Closed
cowwoc opened this issue Mar 11, 2018 · 5 comments
Closed

Consider initializing RateLimiter.mutex eagerly #3066

cowwoc opened this issue Mar 11, 2018 · 5 comments

Comments

@cowwoc
Copy link

cowwoc commented Mar 11, 2018

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.
@cpovirk
Copy link
Member

cpovirk commented Mar 11, 2018 via email

@cowwoc
Copy link
Author

cowwoc commented Mar 11, 2018

@cpovirk Hmm... does this include private final Object mutex = new Object(); as a field (as opposed to inside the constructor)?

@cpovirk
Copy link
Member

cpovirk commented Mar 11, 2018 via email

@cowwoc
Copy link
Author

cowwoc commented Mar 11, 2018

Okay, sad. Feel free to close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants