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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:39:53+00:00 2026-05-15T02:39:53+00:00

I have referenced this previous question as well as other sources, but cannot get

  • 0

I have referenced this previous question as well as other sources, but cannot get CountDownLatch to work correctly.

Background: mainFrame creates new Frame called dataEntryFrame. When dataEntryFrame “Submit” button is clicked, record added to database and dataEntryFrame disposed. At this point, mainFrame should clear and reload a jList that shows all records.

Issue: When dataEntryFrame loads, java freezes, dataEntryFrame components never load.
I cannot get past this part…
then, in the DataEntryFrame, CountDownLatch should only decrements after the submit button is clicked, successfully adds a record to a database table, and disposes itself. Or when the user clicks cancel…

Code: From MainFrame

clearList();
CountDownLatch dataEntryDone = new CountDownLatch(1);
DataEntryFrame f = new DataEntryFrame(dataEntryDone);
Thread newThread = new Thread(f);
newThread.start();
dataEntryDone.await();
reLoadList();

Code: From DataEntryFrame

public void run(){
initComponents();
loadOtherData();
this.setVisible(true);
}
void submit(){
addRecord();
this.dispose()
dataEntryDone.countDown();
}
  • 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-15T02:39:54+00:00Added an answer on May 15, 2026 at 2:39 am

    Use of a new thread for the dataEntryFrame and blocking the mainFrame go against the Swing threading model. In Swing, all calls to UI components in Swing must take place on the Event Dispatch Thread. To verify that this is happening during development, you can install a repaint manager that throws an exception if it detects that UI components are being used from another thread. See FEST – Testing that access to GUI components is done in the EDT. To ensure that something happens on the EDT, you use SwingUtilities.invokeAndWait/invokeLater.

    Your main frame doesn’t (and shouldn’t!) have to wait for the data entry frame, instead of the CountDownLatch, have your data entry frame fire an event to the MainFrame when it is done, so that the MainFrame can take appropriate action, such as refreshing the list.

    Just to muddy the waters still further, saving data to the database and fetching the data for the list should ideally not be done on the event dispatch thread. Instead, use a SwingWorker to perform these operations in their own thread. However, unlike the rule that all UI components must be accessed from the EDT, this rule of background processing is not hard and fast, but is recommended to maintain a responsive UI – if data transfer to/from the db takes any length of time and it’s done on the UI thread (EDT) then the UI will freeze.

    See

    • Sun Totorial on Worker Threads and SwingWorker
    • the Last Word in Swing Threads
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question, like my previous question, references Effective Java . This time I have
I have a table which is referenced by foreign keys on many other tables.
I have a winform application that uses some referenced web services to get data.
At the company I work for we have a Utility project that is referenced
Note that I posed a very similar question earlier but the requirements have since
I have a list of error codes I need to reference, kinda like this:
I have referenced a config file that is located in a solution folder. I
I have a WCF Web Service which is referenced from a class library. After
Following up my previous question , I'm slowly getting the hang of FParsec (though
In a previous question I asked how to implement a client side bad word

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.