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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:09:56+00:00 2026-06-03T10:09:56+00:00

I have an object passed into a function which passes a delayed runnable to

  • 0

I have an object passed into a function which passes a delayed runnable to a handler.

I can lock the object when it gets passed in and when it gets changed using the lock object but then the object needs to get passed out to an ‘alien’ method upload.

How can I ensure this alien method upload does not break the thread safety of my object?

It has objects passed in from elsewhere not just this delay thread so the object lock is not valid and it encompasses quite a lot of functionality so I’m concerned about locking the entire call with the lock object.

private ContentValues mEvent;
protected final Object mEventLock = new Object();

public void delayFunction(final Values e) {

    // Sanity check
    if (e == null) {
        return;
    }

    synchronized (mEventLock) {
        mEvent = e;
    }

    this.handler.postDelayed(new Runnable() {

        @Override
        public void run() {

            if (prefs != null) {
                final String refs = prefs.getPrefs();
                if (refs != null && refs != "") {

                    log.d("refs field: '%s'", refs);

                    synchronized (mEventLock) {
                        mEvent.remove(refs);
                        mEvent.put(refs, 1);
                    }
                }
            }

            synchronized (mEventLock) {
                // Upload event.
                upload(mEvent);
            }

        }
    }, INSTALL_DELAY);
}
  • 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-03T10:09:58+00:00Added an answer on June 3, 2026 at 10:09 am

    I am not sure I understand what you are trying to achieve in your code:

    • delayFunction starts by assigning e to mEvent
    • then you modify mEvents
    • then you upload mEvents

    Why don’t you simply make a local copy of e and work on that copy without synchronization?

    Also, mEvent could be modified by another thread between mEvent = e and the runnable execution because you exit the synchronized block: your runnable would then be working on another e and you will have missed an upload.

    But maybe that’s on purpose.

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

Sidebar

Related Questions

I have the following code, which passes interface into a function which expects a
I have an object obj that is passed into a helper method. public static
I have parsed XML file into objects, in which each object has a 1:1
I have a function which takes as an argument an XDocument object. I need
I have an html file which passes values into a java servlet to insert
I have a function which created a delegated and starts BeginInvoke on that object,
I have a Uri object being passed to a constructor of my class. I
I have a mocked object that is passed as a constructor argument to another
I have a class that occasionally gets passed null for File objects. During normal
I have object A which contains multiple instances of object B, which in turn

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.