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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:58:31+00:00 2026-06-13T01:58:31+00:00

I have a little problem, now I have to work on a small Java

  • 0

I have a little problem, now I have to work on a small Java project. I’m trying to run a few threads from Button event handler; then the last one of the threads must update TextArea on the UI. The threads are doing computational stuff work. The most important part is to make the UI woks fine – I don’t want to freeze the UI and of course I want to update the UI’s TextArea from one of the other threads at regular intervals (not the ui’s one). So here is a part of my code:

Inside Button’s the event handler I’m starting these 4 threads:

Thread generate = new CombinaMaker();
generate.run();

Thread forward = new TranslateForward();
forward.run();

Thread backward = new TranslateBackward();
backward.run();

Thread refresh = new Refresher();
refresh.run();

I want the threads to work simultaneously. The Refresher thread must update the UI TextArea component at regular intervals.

So, here is how I update the UI from Refresher thread:

public static void updateProgress() 
{
    SwingUtilities.invokeLater(new Runnable() 
    {   
         public void run() 
         {
             //HERE
             //I have a loop that have to be looping at every 500 ms
         }
     }
}

My qustion is: am I supposed to do that link this? I need to be simple and effective. This loop is making me sad because it must be looping as long as the application works. May be this is the reason of freezing the UI? I know that I am making big error somewhere, but at this moment I can’t find it alone. May be you can suggest me some simple solution. And the last think – the first 4 threads: I want to start them ‘simultaneously’, without freezing my UI. Is that way (starting them like this from the event handler…) the correct one or may be there is better? Thanks a lot friends!

PS. If the refreshing the UI through my ‘refresher’ thread is hard work I am ready for a compromise variant – Update the UI through his owns thread (UI thread). But in this case may be I must use some ‘time shooting mechanism’ – avoiding the freezing of the UI. What are you thinking?

  • 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-13T01:58:32+00:00Added an answer on June 13, 2026 at 1:58 am

    The main problem is your algorithm. Instead of

    SwingUtilities.invokeLater(new Runnable() {   
        public void run() {
            //HERE
            //I have a loop that have to be looping at every 500 ms
        }
    }
    

    You should have

    // HERE
    // I have a loop that have to be looping at every 500 ms
    // and when something must be updated in the GUI:
    SwingUtilities.invokeLater(new Runnable() {   
        public void run() {
            // update the GUI as fast as possible
        }
    });
    

    i.e.

    while (true) {
        Thread.sleep(500L);
        String update = getUpdate();
        SwingUtilities.invokeLater(new Runnable() {   
            public void run() {
                textArea.append(update);
            }
        });
    }
    

    The runnable passed to SwingUtilities.invokeLater() is executed in the event dispatch thread. It must not execute long-running tasks. Looping endlessly is a very long running task.

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

Sidebar

Related Questions

we have a classical 3-tier-architecture application. Now we face a little problem and we
i have a little problem with my java socket code. I'm writing an android
I am trying to do such conversions, but i have a little problem. Let's
I'm new to MVC3 and have run into a little problem. I've scoured the
I have a little problem when I try to run my Android application. The
I have a little problem with a work item. My goal is to change
I have a little problem: I began a project as a subdirectory in a
I have a little problem right now and I don't know how to fix
I am building a web site from scratch for a little project. I have
I have a little problem. I'm trying to add a timer job following this

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.