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

The Archive Base Latest Questions

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

I just found an interesting situation. Suppose you have some SwingWorker (I’ve made this

  • 0

I just found an interesting situation. Suppose you have some SwingWorker (I’ve made this one vaguely reminiscent of my own):

public class AddressTreeBuildingWorker extends SwingWorker<Void, NodePair> {
    private DefaultTreeModel model;
    public AddressTreeBuildingWorker(DefaultTreeModel model) {
    }

    @Override
    protected Void doInBackground() {
        // Omitted; performs variable processing to build a tree of address nodes.
    }

    @Override
    protected void process(List<NodePair> chunks) {
        for (NodePair pair : chunks) {
            // Actually the real thing inserts in order.
            model.insertNodeInto(parent, child, parent.getChildCount());
        }
    }

    private static class NodePair {
        private final DefaultMutableTreeNode parent;
        private final DefaultMutableTreeNode child;
        private NodePair(DefaultMutableTreeNode parent, DefaultMutableTreeNode child) {
            this.parent = parent;
            this.child = child;
        }
    }
}

If the work done in the background is significant then things work well – process() is called with relatively small lists of objects and everything is happy.

Problem is, if the work done in the background is suddenly insignificant for whatever reason, process() receives a huge list of objects (I have seen 1,000,000, for instance) and by the time you process each object, you have spent 20 seconds on the Event Dispatch Thread, exactly what SwingWorker was designed to avoid.

In case it isn’t clear, both of these occur on the same SwingWorker class for me – it depends on the input data, and the type of processing the caller wanted.

Is there a proper way to handle this? Obviously I can intentionally delay or yield the background processing thread so that a smaller number might arrive each time, but this doesn’t feel like the right solution to me.

  • 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:00:19+00:00Added an answer on May 15, 2026 at 2:00 am

    You can try publishing smaller chunks of the results.

    If that does not help, you might also consider throttling the UI updates instead of the computation. You could moderate the UI update by having process store the NodePairs it receives into a blocking queue:

    @Override
    protected Void doInBackground() {
        this.treeModelUpdater.execute();
        // Omitted; performs variable processing to build a tree of address nodes.
    }
    
    @Override
    protected void process(List<NodePair> chunks) {
        this.queue.addAll( chunks ); // a blocking queue
    }
    
    @Override
    protected void done() {
        // Null Object as sentinel value to unblock TreeModelUpdater
        // and signal it to end doInBackground.
        this.queue.put( new NullNodePair() );
    }
    

    TreeModelUpdater (this.treeModelUpdater) would then be a subordinate SwingWorker implementation whose doInBackground method retrieves and publishes the NodePairs from the queue in a throttled manner.

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

Sidebar

Related Questions

I'm doing some ASP.NET development in VS and have just found an interesting little
I just found an interesting problem between translating some data: VB.NET: CByte(4) << 8
I've just found this interesting presentation about the concept of object oriented CSS. It
I was looking through a code tutorial just now, and found something interesting --
I just found out this weird behavior, is this a bug or what am
In a DELPHI 2007 application that I am developing some prospect clients just found
Googling it a bit I found this to be an interesting question. Would like
I just found an interesting article on ajaxian.com. the article is http://blog.dynatrace.com/2011/03/22/testing-and-optimizing-single-page-web-2-0ajax-applications-why-best-practices-alone-dont-work-any-more/ i wonder
In this question I found an interesting detail about scope of a final variable
I have somewhat interesting development situation. The client and deployment server are inside a

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.