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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:25:40+00:00 2026-05-12T07:25:40+00:00

I am really unfamiliar with working with threads, so I was hoping someone could

  • 0

I am really unfamiliar with working with threads, so I was hoping someone could help me figure out the best way to do this.

I have a JButton in my java application…when you click on the button, I have a Process Builder that creates a process which executes some external python code. The python code generates some files, and this can take some time. When the python code is done executing, I need to load those files into an applet within my Java application.

In its current form, I have a p.waitFor() within the code that calls the external python file…so when you click on the button, the button hangs (the entire application hangs actually) until the process is done. Obviously, I want the user to be able to interact with the rest of the application while this process is going on, but as soon as it’s done, I want my application to know about it, so that it can load the files into the applet.

What is the best way to do this?

Thanks for your help.

  • 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-12T07:25:40+00:00Added an answer on May 12, 2026 at 7:25 am

    You should use SwingWorker to invoke the Python process on a background thread. This way your UI will remain responsive whilst the long-running task runs.

    // Define Action.
    Action action = new AbstractAction("Do It") {
      public void actionPerformed(ActionEvent e) {
        runBackgroundTask();
      }
    }
    
    // Install Action into JButton.
    JButton btn = new JButton(action);
    
    private void runBackgroundTask() {
      new SwingWorker<Void, Void>() {
        {
          // Disable action until task is complete to prevent concurrent tasks.
          action.setEnabled(false);
        }
    
        // Called on the Swing thread when background task completes.
        protected void done() {
          action.setEnabled(true);
    
          try {
            // No result but calling get() will propagate any exceptions onto Swing thread.
            get();
          } catch(Exception ex) {
            // Handle exception
          }
        }
    
        // Called on background thread
        protected Void doInBackground() throws Exception {
          // Add ProcessBuilder code here!
          return null; // No result so simply return null.
        }
      }.execute();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Really ripping my hair out on this one. I have a JAAS Authentication Provider
Really quick jQuery question... I have this function: $(document).ready(function() { $('a#show1').click(function() { $('.item1').toggle(1000); return
Really banging my head with this. I am using isotope http://isotope.metafizzy.co/custom-layout-modes/centered-masonry.html . I have
Really need your help. I have a table that can dynamically add and delete
Really basic question I'm sure for some of you Java heads out there. I
Really wish i was God, then I would understand what this means: The element
I am quite unfamiliar with operating on individual bits. This question is more of
Really I guess I am looking for a best practice answer. I like to
really struggling with this ?? I am very new to Jquery and trying to
I'm unfamiliar with asyncore , and have very limited knowledge of asynchronous programming except

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.