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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:00:43+00:00 2026-05-26T07:00:43+00:00

SwingWorker lets you prepare some data in a background Thread and then use it

  • 0

SwingWorker lets you prepare some data in a background Thread and then use it in EDT. I am looking for a utility that does the opposite: Prepare data in EDT, and then pass it to a background Thread.

If you’re curious, the use case is saving state of a JTable to disk (column order, size, etc.). I need to talk to its model in EDT, but don’t want to write to disk from this thread.

Something like:

void saveCurrentState(final Table table) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            TableColumns state = dumpState(table);
            saveToDisk(table.getTableKey(), state);
        }
    });
}

dumpState() needs to run in EDT. saveToDisk() should NOT run in EDT. The whole thing is deliberately wrapped in invokeLater(), and I cannot replace it with invokeAndWait().

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

    You’re probably looking for ExecutorService. Get one using Executors.newCachedThreadPool() – or the other newXXX() methods, but that one should be okay for most uses.

    That said, I believe this is something you can do with SwingWorker as well. Just prepare your data in the event handler before you create a SwingWorker – you’re already on the EDT there. If you need to initiate this from a non-EDT thread, prepare the data using SwingUtilities.invokeAndWait(), and then spin off another thread to do the writing (or do it in the same non-EDT thread you started with.)

    SwingWorker and ExecutorService provide the same basic service – spin off some work into a background thread without having to manage its lifecycle explicitly. SwingWorker has a convenient method of communicating with the EDT without using invokeLater() all over the place that you don’t need to use, and ExecutorService supports futures as a more general (non-Swing-specific) way of communicating with asynchronous task. For a fire-and-forget use case as yours both are fine.

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

Sidebar

Related Questions

I have a SwingWorker, which does some computations in the background (these actions are
I have a SwingWorker thread that launches a modal dialog box (from a property
I'm trying to debug a horrible exception that is occurring in a SwingWorker thread.
Our Swing application performs some long-running tasks in a background thread using the excellent
I know how to use SwingWorker threads, but I still don't have precise criteria
I have a SwingWorker thread with an IOBound task which is totally locking up
I'm trying to execute a SwingWorker (SubWorker) from another SwingWorker (MainWorker), and then I
I just found an interesting situation. Suppose you have some SwingWorker (I've made this
I currrently have a SwingWorker that sends a HTTP Request and I override the
I want to be able to use SwingWorker subclass multiple times. Is this possible?

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.