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 3433802
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:37:15+00:00 2026-05-18T07:37:15+00:00

Looking through the Android SDK framework source code, I’ve come across this: private final

  • 0

Looking through the Android SDK framework source code, I’ve come across this:


private final class GpsLocationProviderThread extends Thread {

        public GpsLocationProviderThread() {
            super("GpsLocationProvider");
        }

        public void run() {
            Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
            initialize();
            Looper.prepare();
            mHandler = new ProviderHandler();
            // signal when we are initialized and ready to go
            mInitializedLatch.countDown();
            Looper.loop();
        }
    }

(this is from Froyo’s frameworks/base/location/java/com/android/internal/location/GpsLocationProvider.java)

GpsLocationProviderThread is an inner class of GpsLocationProvider, and mHandler is a member instance variable of GpsLocationProvider. This variable is set from within this thread’s run() method, but no synchronization is applied, and mHandler is not volatile.

Why does this work? And even if 99% of the time this does work, it’s not always guaranteed to work, and it’s certainly not good practice. Am I correct in this understanding, or is there something subtle to this code that I’m misunderstanding?

  • 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-05-18T07:37:15+00:00Added an answer on May 18, 2026 at 7:37 am

    The thread is created when the provider is created (in its constructor), and the mInitializedLatch makes sure that the constructor only proceeds once the thread is up and running.

    After that point, mHandler is created and valid, and since the Handler class’ methods are reentrant, this system should be thread-safe. Handler, after all, is a class that is designed for inter-thread communication.

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

Sidebar

Related Questions

Looking through some code I came across the following code trTuDocPackTypdBd.update(TrTuDocPackTypeDto.class.cast(packDto)); and I'd like
I was looking through Mozilla's JS in JS code and came across the snarf
Looking in the android sdk folders, I've found a file called values/config.xml . This
Downloaded ASE from google code, and was looking through tutorials, and available scripts. I
I'm a developer looking to create an Android application to record phone calls. This
Currently I am going through a Sams learn Android SDK in 24 hours book
While looking through the built in Android themes/styles I noticed references to textColorPrimary, textColorSecondary
I've been looking through some of the Android examples on the developer website ,
Looking in the android source for the reboot command we find the following line:
Looking through my server logs, I see that a lot of pages on my

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.