SwingWorker thead does not stop after interrupt?

Hi,
I am using SwingWorker class from Java Tutorial, in order to run a new task thread not in event thread. So I defined a class MyTask that extends SwingWorker, and implements construct() and finish() method (see below for SwingWorker class). Meanwhile, I use a run button to control the task run, that is, when user click the run button the new thread starts by calling MyTask.start(), but I also want to have a Cancel button to stop the task run.
SO in my actionPerformed() for cancel button, I use the following to stop the task, but the problem is that the task does not actually stop running! Any one knows what is the reason and solution? -- Thanks!
     public void cancel() {
          if (task != null) {
               task.interrupt();
          dispose();
     }ps: SwingWorker class from tutorial is also included here.
public abstract class SwingWorker {
    private Object value;  // see getValue(), setValue()
    private Thread thread;
     * Class to maintain reference to current worker thread
     * under separate synchronization control.
    private static class ThreadVar {
        private Thread thread;
        ThreadVar(Thread t) { thread = t; }
        synchronized Thread get() { return thread; }
        synchronized void clear() { thread = null; }
    private ThreadVar threadVar;
     * Get the value produced by the worker thread, or null if it
     * hasn't been constructed yet.
    protected synchronized Object getValue() {
        return value;
     * Set the value produced by worker thread
    private synchronized void setValue(Object x) {
        value = x;
     * Compute the value to be returned by the <code>get</code> method.
    public abstract Object construct();
     * Called on the event dispatching thread (not on the worker thread)
     * after the <code>construct</code> method has returned.
    public void finished() {
     * A new method that interrupts the worker thread.  Call this method
     * to force the worker to stop what it's doing.
    public void interrupt() {
        Thread t = threadVar.get();
        if (t != null) {
            t.interrupt();
        threadVar.clear();
     * Return the value created by the <code>construct</code> method. 
     * Returns null if either the constructing thread or the current
     * thread was interrupted before a value was produced.
     * @return the value created by the <code>construct</code> method
    public Object get() {
        while (true) { 
            Thread t = threadVar.get();
            if (t == null) {
                return getValue();
            try {
                t.join();
            catch (InterruptedException e) {
                Thread.currentThread().interrupt(); // propagate
                return null;
     * Start a thread that will call the <code>construct</code> method
     * and then exit.
    public SwingWorker() {
        final Runnable doFinished = new Runnable() {
           public void run() { finished(); }
        Runnable doConstruct = new Runnable() {
            public void run() {
                try {
                    setValue(construct());
                finally {
                    threadVar.clear();
                SwingUtilities.invokeLater(doFinished);
        Thread t = new Thread(doConstruct);
        threadVar = new ThreadVar(t);
     * Start the worker thread.
    public void start() {
        Thread t = threadVar.get();
        if (t != null) {
            t.start();
}

take a look to this sample.
http://java.sun.com/products/jfc/tsc/articles/threads/threads2.html

Similar Messages

  • Render engine does not stop after reaching 100%

    It looks like to me that the render engine does not stop after reaching 100%. It does not affect the rendered file which is fine and complete
    -the Pause and Stop buttons are displayed but have no effect on pausing or stoping the render
    -when I want to quit SG, it locks up and have to Force Quit to get out of it.
    I really like the program though and hope you are going to fine tune the UI and make it look like After Effect and Premiere.
    I would encourage you to instaure round tripping between these two apps and SG.
    It would be nice to have curves as well.
    Thanks guys
    Brice

    Could you open the defaultTrace.X.trc files and check for the errors?
    Good from my point of view is to make a search if those files for some stack traces with the string ".dsr."
    Regards,
    Aleksandar

  • My MacMini does not stop after giving the order ''switch off''.What can I do?

    My MacMini does not stop after giving the order ''switch off''.
    It stops only, after pushing the button ''on/off'' for some seconds.
    What can I do?
    frahsun

    boot the Mac into safe mode, repair permissions while in it, then reboot normally.
    if that doesn't help, try resetting the System Management Controller (SMC).

  • Capture Now does not stop after the limit is exceeded........

    Hi,
    I'm using FCP HD 4.5 on a DP500 G4, OS 10.3.9. I'm doing "capture Now" to get some VHS video into my machine. FCP will not stop the capture no matter how I set the time limit. This used to work, so what did I do??
    Quite frustrating.
    I've told FCP that I'm using a "non-controllable device" but the capture just keeps on going and going and going..........
    Help......
    Pete D.
    dual 500 G4 Mac OS X (10.3.9)

    When I tell it to stop it responds and stops just fine..... if it's been going for 10 minutes I have a 10 minute long file - even if the limit was 3 minutes......
    What happens when you tell it to stop rather than
    relying on the time limit?
    x
    Do your part in supporting your fellow users. If a
    response has been Helpful to you or
    Solved your question, please mark it as such
    as an aid to other lost souls on the forum.
    Also, don't forget to mark the thread Answered
    when you get enough information to close the thread.

  • Workflow does not stop after the first reject

    Hi!
    We just got a 30-day Microsoft 365 trial at work in which we also received a Share site! I've been playing around with it a lot, especially to help them build an approval process. I believe since this is just a trial, I do not get the globally reusable Approval
    Workflow. So I tried creating a new workflow attached to a list I created.
    In this process, when the list is submitted, it needs to be approved by 2 people sequentially - John Doe & then Billy Bob.
    When I create a new workflow, I click on actions and select "Start Approval Process". After doing that, it populates Step 1 with the following line - Start Approval process on Current Item with these users. I clicked on "these users" link and added the approvers
    in sequences - John Doe, then Billy Bob.
    I saved the workflow, checked for any errors and published the workflow. While testing with this workflow, I realized that when John Doe rejects the process, the task is still assigned to Billy Bob when it is actually suppose to stop.
    How can I stop this workflow right after John Doe rejects the process?
    Any help will be appreciated!

    Hi whocareswhoiam,
    Please post your question to Office 365 forums for quick reply. Below is the link.
    http://community.office365.com/en-us/f/default.aspx
    Thanks for your understanding.
    Best regards,
    Emir

  • The looping does not stop after a true answer, why?

    "Ok, so you want to keep looping as long as the user didn't enter 1, 2, or 0, right?"
    Answer: Yes that's it.
    boolean repeat = false ;
    do {
    System.out.print(" Option 1  \nOption 2 \nOption 0" );
       int x = Integer.parseInt(br.readLine().trim());
          switch(x) {
       case 1 : System.out...etc.("test");
       case 2 : System.out...etc.("test");
       case 0 : System.out...etc.("test");
      default :  repeat = true; 
    } while( repeat == true) ; Steals repeating even if u give a true answer( 1 2 or 0)
    Help! :P

    If you go through the loop once with something other than 0, 1, 2, then repeat will be set to true, and it will never have the possibility to be set to false again.
    Each case should also set repeat to false.
    You should NOT initialize repeat to false at declaration. That way, if you miss one of the repeat = false; settings in the cases, the compiler will give you an error. As you have it now, the same logic error is still present, but the compiler can't detect it.

  • Hi help unlock the phone happened after we installed a new programa we can not get the activation password and ID, I know and still does not stop the phone bought in Israel and what documents should be sent to confirm that my phone Please read through the

    hi help unlock the phone happened after we installed a new programa we can not get the activation password and ID, I know and still does not stop the phone bought in Israel and what documents should be sent to confirm that my phone Please read through the help

    What I am saying is ..........
    The iPhone HAS to be active making calls on the UK carrier network for the carrier to identify as "theirs" and therefore eligible for the Carrier to unlock
    The way to achieve this is to use a PAYG sim making and receiving calls to establish a customer relationship  with the Carrier and then follow the Carrier's process to unlock
    With a PAYG it usually means adding a specified (by the carrier ) amount  usually £15 /£20 depending on the carrier
    This is how O2 function and according to Gemma  this is how Vodafone work

  • Firefox does not stop loading even after the site is loaded and continues as if it is still loading. I have clocked it to 15 minutes, why?

    Firefox does not stop loading even after the site is loaded and continues as if it is still loading. I have clocked it to 15 minutes, why? edit
    Details

    Sorry, I should distinguish between slow loading and manual reloading.
    I understood your problem to be that Firefox never finished loading the page, i.e., some part of the page was loading too slowly.
    By reloading, I meant Ctrl+r (or the reload button), to manually reload the page. You can disregard any cached files and reload all content fresh from the server by adding the Shift key, i.e., Ctrl+Shift+r (helpful when specific sites do not load correctly).
    If the page is automatically reloading itself over and over, that sounds like a completely different problem.

  • My MacBook Pro, does not start after pushing start button. The side bar starts and stops at half way.

    My MacBook Pro, does not start after pushing start button. The side bar starts and stops at half way.

    Hy myneck,
    Happy Holidays!  The resource below may provide some steps to try if your MacBook Pro won't start.
    Troubleshooting: My computer won't turn on - Apple Support
    http://support.apple.com/en-us/TS1367
    This article discusses what to do if your Mac won't turn on. To differentiate this from a display issue, be sure that when you press the power button:
    You don't hear a startup chime.
    You don't hear any fan or drive noise.
    There is no video on your built-in or external display
    If your computer has power but doesn't display any video, it may have one or more of these similar symptoms when you press the power button:
    You may hear a startup chime.
    You may hear fan or drive noise.
    You may see a light from the Sleep LED (if your Mac has one).
    Pressing the Caps Lock key on the keyboard causes it to light. 
    If any of these display-related conditions occur, see Troubleshooting: My computer has no video instead. Otherwise, continue with this article.
    If your computer won't turn on, try each of these steps:
    Verify you have a good connection from your Mac to the wall outlet by confirming the power cord and adapter if present are securely connected and plugged in. To check if the wall outlet is working, plug in a lamp or other electrical device.
    If the wall outlet is working and you continue to have no power try another power cord or adapter if available. If it works you may need a replacement cord or adapter. 
    Note: See Apple Portables: Troubleshooting MagSafe adapters for further troubleshooting with MagSafe adapters.
    Disconnect all accessories that are plugged in to the computer, such as a printer, hub, or other mobile device.
    If your Mac supports user-installable memory, solid state drive, or hard drive, and you recently installed any of these, make sure they are installed correctly and are compatible with your computer. If possible, reinstall the original memory or drive into the computer to find out if the behavior persists afterwards.
    MacBook Pro: How to remove or install memory
    MacBook: How to remove or install memory
    Mac Pro: How to remove or install memory
    Mac mini: How to remove or install memory
    iMac (27-inch, Late 2012): Installing or replacing memory
    iMac: How to remove or install memory
    Reset the SMC.
    If you are still unable to start up your computer after trying each of these steps, visit an Apple Store or Apple Authorized Service Provider (AASP) for further diagnosis. If you plan to visit an Apple Retail Store, make a reservation at the Genius Bar using http://www.apple.com/retail/geniusbar/ (available in some countries only).Note: Diagnostic fees may apply for issues not covered under warranty or the AppleCare Protection Plan (APP).
    I hope this information helps ....
    - Judy

  • Flash player does not work after I installed it

    Flash player does not work after I installed it

    I'm using Mac Osx and my browser is Safari
    Date: Wed, 5 Feb 2014 00:41:29 -0800
    From: [email protected]
    To: [email protected]
    Subject: Flash player does not work after I installed
        Re: Flash player does not work after I installed it
        created by Mike M in Installing Flash Player - View the full discussion
    This is a user-to-user forum, NOT 24/7 support. You're "lucky" I happen to be up at 1:40 am to answer you.
    What OS are you using?
    http://mmonlinedesigns.com/images/os.png
    What browser?
    http://mmonlinedesigns.com/images/browsers.png
         Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/6087541#6087541
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/6087541#6087541
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/6087541#6087541. In the Actions box on the right, click the Stop Email Notifications link.
               Start a new discussion in Installing Flash Player at Adobe Community
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/thread/416458?tstart=0.

  • I have a new Macbook pro, about 2 months old, and at times running video, the fans starts and does not stop. how do you get it to stop.

    I have a new Macbookbook, about 2 months old, and at times running video, the fans starts and does not stop. how do you get it to stop. Also i am thinking once the video is done  the fan should be slowing down and getting quiet on its own.

    Your fan(s) will run at high speed (i.e., loudly) while video is playing, and you can't get around that.
    If your fans are not slowing down within 2-4 minutes after CPU- and/or GPU-intensive usage ends, and the application that was showing the video is still running, Quit that application. (In fact, if you're accustomed to Windows, you may not realize that simply closing a Mac application's window does not quit the application. You still need to use the Quit command in the application-name menu. There will always be a bright dot beside or below the application icon in your Dock for each application that is open.) Quit the ones you aren't using, and see whether that allows the fans to slow down without restarting the machine. If that doesn't do the trick, reset the SMC:
    http://support.apple.com/kb/HT3964?viewlocale=en_US&locale=en_US

  • PCI wireless card does not work after restart - FM2-A55M-E33

    Installed TP-LINK WN751ND wireless PCI card onto FM2-A55M-E33 motherboard. The card works fine after cold start, but does not work after restart. Windows recognises the card, but it gets code 10, cannot start.
    BIOS is updated (v.11.1), as well as drivers and Windows 7 64.
    I suspect that this might be the issue: Incorrect ASPM Transitions on the GPP Interface as found in ChipsetMotherboard_TechDocs/48671.pdf on AMD's official support site.
    Does anyone know more about this issue?

    Great! I've done that and now my card shows up. Thing is, when I try to get an IP address, it won't work. Here is the command output:
    ieee80211 phy0: wl_ops_config: change monitor mode: false (implement)
    ieee80211 phy0: wl_ops_config: change power-save mode: false (implement)
    ieee80211 phy0: wl_ops_bss_info_changed: qos enabled: false (implement)
    And then it times out and no IP is assigned. The thing is, wpa_supplicant stays alive after this time out, and I am unable to kill it (killall -9 wpa_supplicant won't kill it). At this point if I try to reboot the machine, it will stop at 'Rebooting' and won't go anywhere. If I turn off the wireless card in its switch Linux crashes. If I try to get an ip again (by running dhcpcd) the command will hang and not return to the shell anymore.
    I am unable to find any useful information in the logs.
    Got any more suggestions?
    Thanks! (And sorry to disturb so much)

  • My Adobe acrobat X Pro does not respond after a minute I open up a pdf file

    I recently have installed Adobe Master Suite CS6 Collection. My Adobe acrobat X Pro does not respond after a minute I open up a pdf file. This happens every time when open a new pdf file. My operating system is Windows 7 pro ( Lenovo-64 bits). Any suggestions would be appreciated !!

    Mylenium
    Thank you for the suggestions.
    I checked the WIndows log files. It reported the following error:
    The program Acrobat.exe version 10.1.1.33 stopped interacting with Windows and was closed. To see if more information about the problem is available, check the problem history in the Action Center control panel.
    Process ID: 4770
    Start Time: 01d0079a09bba381
    Termination Time: 13
    Application Path: C:\Program Files (x86)\Adobe\Acrobat 10.0\Acrobat\Acrobat.exe
    Report Id: 4f145db6-7391-11e4-8fc1-005056c00001
    I ran for the memory diagnostics as it showed the error with video card error. My NVDIA graphics card is not working properly. Do you think that could be a problem?I am running on Windows 7 64 bit computer. It also complains about the incompatibility with 64 bits.
    Thank you.

  • Synchronization does not stops

    Hi all
    After installing MI, MAM etc, during the Synchronization for the data (5000 measurement points), the data comes but the Synchronization does not stops or takes a very long time to stop. Confirmed about the data by tracking the memory and also by restartign the device once the memory is stable, the data exists.
    Similarly while creating measurement documents for 150 docuemtns syn works fine, but for 300 documents the data gets successfully posted but the sync does not stops unitl we manually restart the device.
    We use Symbol 9090 and program memory available is 2 to 3 MB.
    Is it a memory issue??  Did any one had come accross this problem??
    Thanks
    Raj

    Hi Raj
      Surprised that these recomendations doesnt work. Anyway i have one more recomendation which is related to TIME AGENT. If you are using any of the Agent feature, which is made available recently in MI then this could also result in an endless sync. The Time agent which is one of the several Agents, can never have a value TRUE for the History parameter. As for the possible solution,  please change the value of AGENT_HISTORY in the TIME_AGENT parameter set to FALSE and then assign this parameter set to a device configuration which inturn in assigned to a device.  Please test this new scenario with a fresh client installation and not with an already synced client. This should solve this endless problem.
    Or other way of testing this is In the client there is a file named <b><i>agents.properties</i></b> in the MI settings folder. Here there would an entry called TRACE_AGENT#AGENT_HISTORY=TRUE. Please set his value to FALSE. Let me know if this works.
    Best Regards
    Sivakumar

  • Enqueue replication server does not terminate after failover

    Hi,
    We are trying to setup high availability of enqueue server where in we have running enqueue server on node-A and ERS on node-B all the time.
    Whenever enqueue is stopped on node-A, it automatically failovers on node-B but after replication of lock table, enqueue does not terminate the ERS running on node-B and as a result our enqueue and ERS both keeps running on the same host (Failover node-B) which should not be the case.
    We havenu2019t configured polling in that scenario SAP note-1018968 depicts the same however this is applicable only for version-640 and 700.
    Ideally when enqueue server switches to node-B, it should terminate the ERS on the same node after replication and then HA software would take care of its restart on node -A.
    We have ERS running of version 701; could anyone please let me know if the same behaviour is common for 701 version as well?
    Or there is any additional configuration to be done to make it working.
    Thanks in advance.
    Cheers !!!
    Ashish

    Hi Naveed,
    Stopping ERS is suppose to be taken care by SAP only and not the HA software.
    Once ERS stops on node -B there would be a fault reported and as a result HA software will restart the ERS on node A.
    Please refer to a section of SAP Note 1018968 - 'Enqueue replication server does not terminate after failover'
    "Therefore, the cluster software must only organise the restart of the replication server and does not need to do anything for the shutdown."
    Another blog about the same:
    http://www.symantec.com/connect/blogs/veritas-cluster-server-sap  
    - After the successful lock table takeover, the Enqueue Replication Server will fault on this node (initiated by SAP). Veritas Cluster Server recognizes this failure and initiates a failover to a remaining node to create SAP Enqueue redundancy again. The Enqueue Replication Server will receive the complete Enqueue table from the Enqueue Server (SCS) and later Enqueue lock updates in a synchronous fashion.
    So it is nothing about HA software, it is the SAP which should control ERS on node-B.
    Cheers !!!
    Ashish

Maybe you are looking for