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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:58:00+00:00 2026-05-19T11:58:00+00:00

The Following class DoStuff starts a thread and syncs to protect the listener object

  • 0

The Following class DoStuff starts a thread and syncs to protect the listener object from being accessed when null.

Now when accessing the DoStuff class function setOnProgressListener() externally I’m having issues because the call is getting held for a long time before it exits the function call. I’m not sure why this happens? I seems as if the synchronization has queued up a lot of calls? Any input on this would help!

I’m essentially passing null to the listener because I no longer wish to get updated for this status. I do this as part of my process to kill the DoStuff Thread.

Thanks!

public class DoStuff extends Runnable
{
    Object MUTEX = new Object();
    private OnProgressListener mOnProgressListener  = null;

    public DoStuff()
    {
        new Thread(this).start();
    }

    public void setOnProgressListener( OnProgressListener onProgressListener )
    {
        synchronized (MUTEX) 
        {
            mOnProgressListener = onProgressListener;
        }
    }

    private void reportStatus( int statusId )
    {
        synchronized (MUTEX) 
        {
            if (null != mOnStatusListener)
            {
                mOnStatusListener.setStatusMessage(new OnStatusEvent(this, statusId));
            }
        }
    }

    // this is the run of a thread
    public void run()
    {
        int status = 0;
        do
        {
            // do some work and report the current work status
            status = doWork();
            reportStatus( status );
        } while(true);
    }
}
  • 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-19T11:58:01+00:00Added an answer on May 19, 2026 at 11:58 am

    Thanks all for your help. I was able to determine why the indefinite lock. Something important and obvious is that once I run the reportStatus() function call it will hold the lock MUTEX until it is completely done executing the callback. My fault was that at the registered callback I was calling setOnProgressListener(null) by mistake. Yes, I admit didn’t post enough code, and most likely all of you would have catched the bug… So calling setOnProgressListener(null) would wait until the MUTEX object has been released, and the reportStatus() was held waiting to call setOnProgressListener(null), therefore I was in a deadlock!

    Again the main point I learned is to remember that triggering a callback message will hold until the registered callback function is done processing it’s call.

    Thanks all!

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

Sidebar

Related Questions

Consider the following Java class: public class Foo { public static void doStuff() {
In the following snippet: public class a { public void otherMethod(){} public void doStuff(String
The following class is not thread-safe (as proven in Proving the following code not
The following class is used by another program. When it is accessed, it throws
Imagine the following code: MyService myService = new MyService(); myService.Start(); myService.DoStuff(); The MyService class
For example, the following MXML script attaches a listener to a Button class: <mx:Button
I have the following classes class Parent { virtual void doStuff() = 0; };
I have the following class public class classB : classA which contains function dostuff
I have a class that contains a QMap object: QMap<QString, Connection*> users; Now, in
Following class structure is given: class Job { String description; Collection<JobHistory> history; } class

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.