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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:26:12+00:00 2026-06-18T05:26:12+00:00

I am trying to make use of HandlerThread in android and am ending up

  • 0

I am trying to make use of HandlerThread in android and am ending up with either a situation in which the UI thread is not responding anymore, or a strange IllegalStateException. I want to give you a minimal example of my problem.

I have a class DataManager which instantiates a worker thread on creation:

public class DataManager
{
    private final HandlerThread loaderThread = new HandlerThread( "Worker" );
    private final Producer loader;

Inside of this class I have my Handler defined:

    private static class Producer extends Handler
    {
        public Producer( Looper looper )
        {
            super( looper );
        }

        @Override
        public void handleMessage( Message msg )
        {
            msg.recycle();
        }
    }

The constructor of my DataManager runs the worker thread and associates the handler with the thread’s looper:

    public DataManager()
    {
        loaderThread.start();
        this.loader = new Producer( loaderThread.getLooper() );
    }

Before DataManager is destroyed, it stops the thread and waits for it to finish. Actually I believe this part is not relevant to my problem, because my DataManager instance is definitely alive all the time:

    @Override
    protected void finalize() throws Throwable
    {
        loaderThread.quit();
        loaderThread.join();

        super.finalize();
    }

Finally, I have doSomething method, which simply posts a message to the worker thread:

    public void doSomething()
    {
        Message msg = Message.obtain();
        loader.sendMessage( msg );
    }

Now I’m instantiating the DataManager from inside of a custom view on the UI thread. When the view is about to paint itself using onDraw it calls doSomething on the DataManager. The further behavior depends on whether an AsyncTask is currently running in background or not:

  • If it is running, than the UI thread is becoming unresponsive form this moment on.
  • Otherwise, I get an IllegalStateException, thrown from within a subroutine of Looper.loop of the UI thread, saying:

    IllegalStateException: The specified message queue synchronization barrier token has not been posted or has already been removed.

Google gives absolutely no results for this message. I’ve been reading documentation and searching for similar problems for a few hours now and still have no idea what I might be doing wrong. Any ideas?

  • 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-18T05:26:14+00:00Added an answer on June 18, 2026 at 5:26 am

    Got it. Obsiously the situation about recycling messages is this:

    If you send it to a handler, the handler/looper will recycle it for you.

    So one must not recycle the message within handleMessage.

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

Sidebar

Related Questions

I'm trying to make use of Vexflow ( http://vexflow.com/ ) on the Android. However,
I'm trying to make use of FlowCover -> http://www.chaosinmotion.com/flowcover.m but it is not working.
I am trying to make use of boost::thread to perform n similar jobs. Of
Being new to android, I’m having some issues. Currently I’m trying to make use
I'm trying to make use of a function which comes in a 3rd party
I am trying to make use of jQueryUI AJAX tabs in my ASP.Net Webforms
I'm trying to make use of parallel processing with the wordnet package for R
I'm writing some error checking and trying to make use of an boolean array
I am in the process of evaluating FindBugs and am trying to make use
I'm trying to make getJSON to use JSONP object, but I can't figure out

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.