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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:50:53+00:00 2026-05-28T20:50:53+00:00

I have a JFrame that shows a preview content, since the loading of preview

  • 0

I have a JFrame that shows a preview content, since the loading of preview data could take several times i decided to put the loading operation into a SwingWorker, here’s a code sample :

public void setPreviewContent(final String content) {

SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {

    @Override
    protected Void doInBackground() throws Exception {

        frame.setCursor(java.awt.Cursor.getPredefinedCursor(
            java.awt.Cursor.WAIT_CURSOR));
        //DO My Work
        return null;
    }

    @Override
    protected void done() {
         frame.setCursor(java.awt.Cursor.getPredefinedCursor(
         java.awt.Cursor.DEFAULT_CURSOR));
    }
};
worker.execute();
}

My frame it is initialized each time that is shown and is disposed each time that is closed with :

frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

After the initialization and that is show the setPreviewContent() method is called and it work properly, the only problem is that each time i close and reopen the preview frame a Daemon Thread is created and is left running :

Threads Leak

As you can see soon a huge number of threads remain in running state, causing a leak.
How can i resolve the problem ?

If i use a standard Thread i don’t have this problem …

  • 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-28T20:50:54+00:00Added an answer on May 28, 2026 at 8:50 pm

    The JavaDoc says:

    Schedules this SwingWorker for execution on a worker thread. There are
    a number of worker threads available. In the event all worker threads
    are busy handling other SwingWorkers this SwingWorker is placed in a
    waiting queue.

    Did you try to close and reopen it more than 6 times, to see, whether eventually no new Thread is added? My guess is that you didn’t reach the thread pool limit yet.

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

Sidebar

Related Questions

I have this main JFrame (call it DrinkChooser) that shows another complex confirmation JFrame
I have a main controller class that shows a JFrame containing a JTable and,
I have a JFrame that contains a display JPanel with JTextField and a control
This one's a tough one - I have a JFrame that generates JTextFields. When
Java Newbie here. I have a JFrame that I added to my netbeans project,
My current problem is that I have a JFrame with a 2x2 GridLayout. And
I have this class called PollFrame that extends JFrame in a file called PollFrame.java
I have a program that creates a JFrame and makes it visible. Is there
I have an application that is works fine and the JFrame for it is
I have a JFrame that accepts top-level drops of files. However after a drop

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.