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

  • Home
  • SEARCH
  • 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 537645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:56:55+00:00 2026-05-13T09:56:55+00:00

Is there a way of Holding a thread in a State waiting for changes?

  • 0

Is there a way of Holding a thread in a State waiting for changes?
I mean wait tll something happend (change var, call method, etc..)
perhaps it needs using Event Listeners, or synchronized objects/methods..

The usual aproach for statemachines like this

statemachine example

That uses a do{..}while(true) loop that could work for singled threaded(and no GUI) application but it CANT’T be used with threads..
(at least you want to use a core for every threaded state machine)

So to avoid that processor consuming task a simple (and ugly) way
is a “periodic checker”, I mean adding a Sleep
other idea is defining a synchronized object and using wait instead of thread Sleep

example:

do{
    Switch(state)
    {         
        case STATE_A:
            //..A things                         
            break;

        case STATE_B:
            //..B things                         
            break;

        ...

        case STATE_Z:
            //..Z things                         
            break;
    }
    // Here!  =>   wait()?  Thread.sleep(TIME_CONST)? //Hold and yield
}while(powerOn);

The drawback is adding complexity using synchronized or that anything that happen within TIME_CONST would be invisible

I would like to know other ideas for doing this,
thanks !

  • 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-13T09:56:56+00:00Added an answer on May 13, 2026 at 9:56 am

    Yes, you would be using wait/notify. That is what it is for.

    Or maybe your state machine does not need to have its own thread. Other threads could call an update method on the state machine when something interesting happens.

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

Sidebar

Related Questions

Is there a way to test if the current thread is holding a monitor
Is there a way to do something similar to a SourceSafe label in svn?
Is there any way to change the BackColor of the border of a panel
Is there any way to change the firefox shift hotkey that makes firefox start
Is there a way to wait for geocoder to invoke didFailWithError or didFindPlaceMark? My
Is there a way to detect if the user is holding down the shift
Is there any way to stop an iframe re-loading its contents when I change
Is there a way to instantiate objects from a string holding their class name?
Duplicate: Is there a way to instantiate objects from a string holding their class
is there way how to get name ov event from Lambda expression like with

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.