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

Use the double-check idiom with a volatile field. #256

Merged
merged 1 commit into from
Mar 21, 2022

Conversation

robxyy
Copy link
Contributor

@robxyy robxyy commented Mar 19, 2022

synchronized (TracingProviderImpl.class) {
if (iTracing == null) {
iTracing = TracingImpl.build(supplier, tracing);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if(xxx!=null){
    return xxx;
}
//init xxx
if(xxx!=null){
   return xxx;
}

//init xxx
if(xxx!=null){
   return xxx;
}
if(xxx==null){
   //init xxx
   if(xxx==null){
      //init xxx  
       if(xxx==null){
          //init xxx
       }
   }
}
return xxx;

The first is more readable than the second, because the first is less nested.
At the same time they achieve the same purpose, so I don't understand why you modify this piece of code

@Oseenix
Copy link
Contributor

Oseenix commented Mar 21, 2022

Effective Java #Item 71

Thank you for your PR. It's not necessary to revert and rebase next time, so everyone can review on the changes. If any change required, just modify and push again. Finally, we use squash and merge make it looks like one commit.

@haoel
Copy link
Contributor

haoel commented Mar 21, 2022

@robxyy it's fine to push iteratively rather than push forcibly because we'd like to see the historical review comments and the changes. Don't worry about many commits after the merge, because we are going to do the squashing merge.

@observeralone
Copy link
Contributor

@robxyy
Do you still want to change the code to push?
If not I will merge it.

@robxyy
Copy link
Contributor Author

robxyy commented Mar 21, 2022

@Oseenix @haoel Thanks for the explanation, I'll pay attention next time.
@observeralone Please merge it. 🍺

@observeralone observeralone merged commit 52f6744 into megaease:master Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants