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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:47:42+00:00 2026-06-04T11:47:42+00:00

In my android application I’ve got a callback from a native thread into Java

  • 0

In my android application I’ve got a callback from a native thread into Java code which needs to be synchronized with the main UI thread. The intention is that the UI thread display a list of options based on information returned from the native thread. Until the user selects an option the native thread needs to block. After the user selects an option the native thread reads the value and continues running.

I’ve tried to implement this solution using a ConditionVariable however I get a VM error with the comment indicating “Fatal spin-on-suspend, dumping threads”.

It looks as if it’s not possible to use a Java based synchronization object to synchronize these threads. The code works perfectly in the case where I’ve got two Java threads.

In general is there any way to use a Java based synchronization object to synchronize a Java and native thread, or does this need to be implemented using the NDK with a call from the Java thread into an NDK function that implements the synchronization?

  • 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-04T11:47:44+00:00Added an answer on June 4, 2026 at 11:47 am

    The way to do this is not to use a Java based sync object but rather an NDK based sync object as follows:

    static pthread_cond_t  uiConditionVariable  = PTHREAD_COND_INITIALIZER;
    static pthread_mutex_t uiConditionMutex     = PTHREAD_MUTEX_INITIALIZER;
    
    
    
    /**
     * This function opens the condition variable which releases waiting threads.
     */
    JNIEXPORT void JNICALL
    Java_com_Xxxx_openConditionVariable(JNIEnv *env,jobject o)
    {
        pthread_mutex_lock(&uiConditionMutex);
        pthread_cond_signal(&uiConditionVariable);
        pthread_mutex_unlock(&uiConditionMutex);
    }
    
    /**
     * This function blocks on the condition variable associated with the 
     */
    JNIEXPORT void JNICALL
    Java_com_Xxxx_blockConditionVariable(JNIEnv *env,jobject o)
    {
        pthread_mutex_lock(&uiConditionMutex);
        pthread_cond_wait(&uiConditionVariable,&uiConditionMutex);
        pthread_mutex_unlock(&uiConditionMutex);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Android application which has the main UI thread, and several other
My android application needs to display time which has to be incremented according to
my Android application needs to play .swf files, which are sound only.. Is there
My android application needs another NATIVE application executable to run before the android one,
My Android application uses Java OAuth library, found here for authorization on Twitter. I
In Android application development, I frequently go through the word CallBack in many places.
My android application sends a web service request and gets the response from web
In my Android application I get a response from a server in HTML format,
My Android application is expecting and array of usernames from my WCF Service using
I have android application that is written regular way. layouts, java, APK. Now, depending

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.