Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8462509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:10:51+00:00 2026-06-10T14:10:51+00:00

In a Sonar report at work we have a few warnings for an Android

  • 0

In a Sonar report at work we have a few warnings for an Android project:

Multithreaded correctness – Incorrect lazy initialization of static field
findbugs : LI_LAZY_INIT_STATIC

In order to correct these issues I was directed to the wikipedia entry on double checked locking

http://en.wikipedia.org/wiki/Double_checked_locking_pattern#Usage_in_Java

When I look through the android framework code, I do not see double checked locking employed for example, the WebViewDatabase class just makes its getInstance(Context) method synchronized:

public static synchronized WebViewDatabase getInstance(Context context) {
    if (mInstance == null) {
        mInstance = new WebViewDatabase(context);
    }
    return mInstance;
}

What is the right way in Android?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:10:53+00:00Added an answer on June 10, 2026 at 2:10 pm

    public static synchronized WebViewDatabase getInstance is not using double checked locking so it does not have that problem. For double checked locking you check outside of the lock if the instance exists and skip the lock if that is the case. That results in faster execution than always locking since you only need to lock once at the very beginning.

    If it was using double checked locking it would look like

    public static WebViewDatabase getInstance(Context context) {
        if (mInstance == null) {
            synchronized (WebViewDatabase.class) {
                if (mInstance == null)
                    mInstance = new WebViewDatabase(context);
            }
        }
        return mInstance;
    }
    

    and mInstance would need to be defined volatile

    There is no change regarding synchronization / singletons / double checked locking for Android vs desktop Java

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just configured Sonar to analyse my android project but realized that only the
I'd like to create a report in Sonar for the most actively edited files.
I have installed sonar and it works on http://localhost:9000 When I want to analyze
I am setting up a Sonar project (using the delphi plugin), for simplicity sake
I have a custom defined table in sonar DB , and I wanted to
Good morning, i've got a question about cobertura report integration in sonar. I've tried
I am using sonar for code analysis in my current project and my question
I would like to create two sets of Sonar reports from the same project.
I have a Sonar desk setup and an Eclipse (Indigo) IDE setup. I have
I have unzipped the sonar(code review tool) and started by executing batch file on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.