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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:57:35+00:00 2026-05-29T04:57:35+00:00

I am having some problems cancelling a swing worker. I am unsure after reading

  • 0

I am having some problems cancelling a swing worker. I am unsure after reading the documentation how to approach solving this

sw = new SwingWorker<Object, Void>()
{     
    Object o;
    protected Object doInBackground() throws Exception      
    {          
    //do some long running task via a method call
    } 
}

Then in my cancel button handler i just want to call sw.cancel(true);

This doesnt seem to be working though. According to the documentation the swing worker needs to no how to cancel iteslf. But, if the method to run the swing worker is only being calld once then how do i account for this with thread.sleep(which is what i’ve read is one way of fixing)

Thanks

  • 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-29T04:57:37+00:00Added an answer on May 29, 2026 at 4:57 am

    Swing will actually monitor your work with a Future. When you try to cancel the worker Swing will invoke future.cancel(true) (the true value will attempt to interrupt() the executing thread).

    What this means is your work needs to respond to interruption. If the long running computations don’t respond to interruption you will have to put in some checkpoints and respond accordingly

    protected Object doInBackground() throws Exception      
    {          
       //do part 1 of long running task
       if(Thread.currentThread().isInterrupted()){
         //clean up and return
       }
       //do part 2 of long running task
       if(Thread.currentThread().isInterrupted()){
         //clean up and return
       }
       //etc..
    } 
    

    Swing will simply notify the executing thread that it should cancel. It is your responsibility to actually enforce cancellation.

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

Sidebar

Related Questions

I'm having some problems with a datagridview element I'm using in VS2008. This DataGridView
Im having some problems with binding in wpf/xaml. Have this simple file: <Window x:Class=test.Window1
I'm having some problems wrapping my head around how to do this. I have
Having some problems figuring out the regex to match this: function Array() { [native
After having some problems with these two linker errors on SO , I have
Having some problems with getting some ajax script to work. Using this as the
I'm having some problems figuring out a solution to this problem. I want to
Having some problems with IE7 on jquery $.each, this gives me an Object does
Ive been having some problems with understanding the MySql reader from MySql.Data.MySqlClient This is
I am having some problems getting this Wordpress nav bar to render correctly in

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.