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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:01:15+00:00 2026-06-10T08:01:15+00:00

How can you create a function or component etc that will stop all running

  • 0

How can you create a function or component etc that will stop all running code until a condition is met?

For example the same way as a JOptionPane will do, if I have this for example:

JOptionPane.showInputDialog(null, "Hello", "Title", 1);

Within a function etc and then print to the console afterwards it it will not print until I close the JOptionPane.

I am guessing this component has some sort of thread setup built in to do this but how could I duplicate that with my own functions?

So say for example I wanted to make JFrames delay everything until it was closed so it acts like a JOptionPane.

Or for example have a function that had multiple inputs which got updated and inside it did some maths with those and if it was a certain value returned a boolean, but then everything else but those was paused until the true boolean was returned.

I am guessing the solution is some sort of thread setup but I am quite new to Java and when I have coded in the past I have not really used threads so I cannot create a good stop-start/pause-run style function system yet.

Does anyone have any suggestions how to achieve this or better yet code examples showing this type of thing working?

  • 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-10T08:01:16+00:00Added an answer on June 10, 2026 at 8:01 am

    You create a monitor (which is just a simple Object)

    public static final Object monitor = new Object();
    public static boolean monitorState = false;
    

    Now you create a wait method

    public static void waitForThread() {
      monitorState = true;
      while (monitorState) {
        synchronized (monitor) {
          try {
            monitor.wait(); // wait until notified
          } catch (Exception e) {}
        }
      }
    }
    

    and a method to unlock your waiters.

    public static void unlockWaiter() {
      synchronized (monitor) {
        monitorState = false;
        monitor.notifyAll(); // unlock again
      }
    }
    

    So when you want to do something fancy, you can do it like this:

    new Thread(new Runnable() {
      @Override
      public void run() {
        // do your fancy calculations
        unlockWaiter();
      }
    }).start();
    
    // do some stuff    
    waitForThread();    
    // do some stuff that is dependent on the results of the thread
    

    Of course, there are many possibilities, this is only one version of how to do it.

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

Sidebar

Related Questions

I can create function pointers in Fortran 90, with code like real, external ::
I would like to create a function that can deal with an object that
I'm looking for a way to create a function that can be used in
I'm looking to create a PHP function that can trim each line in a
My goal is to create some kind of swing component that can do two
in C++, I can easily create a function pointer by taking the address of
How can I create an update function in javascript/jquery? An update function is a
It's possible to call C functions through CREATE FUNCTION but how can .NET functions
How can I create an anonymous and curried function in Scala? The following two
How can I create a buffer in linux kernel without malloc() function (or calloc()

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.