SwingWorker done() is called BEFORE process() when publish() used

I'm using SwingWorker to build a list of files by recursively searching a directory. As a file is found I call publish(file). In my process() method I add the file(s) to a list model, which updates a JList. I also have a PropertyChangeListener attached to the SwingWorker so I know when its done. The listener calls listModel.getSize() when done, so I can determine wheter to enable a 'Clear List' button. When only a few files are found, SwingWorker is done() before process() has added the files to the model, so the size is 0 and the button is not enabled.
Mu question is how can I get SwingWorker to call process() before calling done()?
Thanks

Mu question is how can I get SwingWorker to call
process() before calling done()?I have run into the same problem. It's ugly. The least Java could do is offer a flush() method. At best, they'd fix this problem and flush any publish()ed objects before calling done(). I've worked around it for now with a hack. I simply publish a null to signal completion in doInBackground(). I don't even override done() any more. Of course, I'm assuming publish() order is maintained (evidence so far supports this assumption).
The only other option I'm aware of is invokeLater().
Andrew

Similar Messages

  • SwingWorker done() is called before doInBackground is finished

    Hi,
    I'm having a problem understanding how the SwingWorker works. According to java docs: "After the doInBackground method is finished the done method is executed" and there is a happens before relationship. But if I run the code below:
       public class A extends SwingWorker<Void, Void>
             protected Void doInBackground() throws InterruptedException
                  String k = "this is a test";
                  String j = k;
                  while(true)
                       for(int i=0; i<1000; i++)
                            j = j + k;
                            j.replaceAll("nothing", "something");
                       System.out.println("going");
             protected void done()
                  try
                       get();
                  catch(InterruptedException ex){System.out.println("interrupted");}
                  catch(CancellationException ex){System.out.println("cancelled");}
                  System.out.println("done");
    }and call cancel(true) while the thread is running the output I get is
    going
    going
    cancelled
    done
    going
    going
    So that means that done() get's fired after I called cancel(), not after doInBackground() is finished.
    This is causing some serious problems in my actual application, as I do some clean up in done(), but doInBackground() keeps going until it hits my Thread.sleep() code.
    Thanks a lot.

    Hello,
    I think I have a workaround to your problem. By the way, I am the one who submitted [bug 6826514|http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6826514] in April of 2009.
    My solution takes advantage of firePropertyChange() and related methods in SwingWorker.
    Here I completely refrain from using done() method to detect the end of doInBackground()'s execution.
    Please bear with me the fact that the code is a little bit long.
    /* GoodWorker.java  */
    package solve;
    import java.beans.PropertyChangeEvent;
    import java.beans.PropertyChangeListener;
    import javax.swing.SwingWorker;
    * @author Sumudu
    public class GoodWorker extends SwingWorker<Void, Void> {
        private MainFrame mainFrame = null;
        private final String prReallyDone = "ReallyDone";
        private void whenReallyDone() {
            mainFrame.afterWorkerFinishes();
            System.out.println("done");
        public GoodWorker(MainFrame mainFrame) {
            this.mainFrame = mainFrame;
            getPropertyChangeSupport().addPropertyChangeListener(prReallyDone,
                new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent e) {
                    if (e.getNewValue().equals(true)) {
                        whenReallyDone();
        protected Void doInBackground() throws Exception {
            String k = "this is a test";
            String j = k;
            while (!isCancelled()) {
                for (int i = 0; i < 1000; i++) {
                    j = j + k;
                    j.replaceAll("nothing", "something");
                System.out.println("going");
            firePropertyChange(prReallyDone, false, true);
            return null;
    // -- The End --
    /* BadWorker.java */
    package solve;
    import javax.swing.SwingWorker;
    public class BadWorker extends SwingWorker<Void, Void> {
        private MainFrame mainFrame = null;
        public BadWorker(MainFrame mainFrame) {
            this.mainFrame = mainFrame;
        protected Void doInBackground() throws Exception {
            String k = "this is a test";
            String j = k;
            while (!isCancelled()) {
                for (int i = 0; i < 1000; i++) {
                    j = j + k;
                    j.replaceAll("nothing", "something");
                System.out.println("going");
            return null;
        @Override
        protected void done() {
            mainFrame.afterWorkerFinishes();
            System.out.println("done");
    // -- The End --
    /* MainFrame.java */
    package solve;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.concurrent.CancellationException;
    import java.util.concurrent.ExecutionException;
    import javax.swing.SwingWorker;
    public class MainFrame extends javax.swing.JFrame {
        private BadWorker badWorker = null;
        private GoodWorker goodWorker = null;
        private boolean useGoodWoker;
        private void initialize() {
            this.setLocationRelativeTo(null);
            btnStop.setEnabled(false);
            useGoodWoker = chkUseGoodWorker.isSelected();
            btnStart.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    chkUseGoodWorker.setEnabled(false);
                    btnStart.setEnabled(false);
                    btnStop.setEnabled(true);
                    useGoodWoker = chkUseGoodWorker.isSelected();
                    System.out.println("Starting SwingWorker...");
                    if (useGoodWoker) {
                        goodWorker = new GoodWorker(MainFrame.this);
                        goodWorker.execute();
                    } else {
                        badWorker = new BadWorker(MainFrame.this);
                        badWorker.execute();
            btnStop.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    SwingWorker worker = (useGoodWoker ? goodWorker : badWorker);
                    if (worker != null && !worker.isDone()) {
                        btnStop.setEnabled(false);
                        worker.cancel(true);
        public void afterWorkerFinishes() {
            SwingWorker worker = (useGoodWoker ? goodWorker : badWorker);
            try {
                worker.get();
            } catch (InterruptedException ie) {
                System.out.println("Got interrupted while waiting in get().");
            } catch (ExecutionException ee) {
                System.out.print("An exception was thrown inside doInBackground(). ");
                Throwable t = ee.getCause();
                System.out.printf("More specifically, %s %n", t.getMessage());
            } catch (CancellationException ce) {
                System.out.println("SwingWorker got cancelled by you.");
            chkUseGoodWorker.setEnabled(true);
            btnStart.setEnabled(true);
        /** Creates new form MainFrame */
        public MainFrame() {
            initComponents();
            initialize();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
        private void initComponents() {
            chkUseGoodWorker = new javax.swing.JCheckBox();
            buttonPanel = new javax.swing.JPanel();
            btnStart = new javax.swing.JButton();
            btnStop = new javax.swing.JButton();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("SwingWorkers");
            chkUseGoodWorker.setText("Check this to use Good Worker");
            chkUseGoodWorker.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
            chkUseGoodWorker.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
            chkUseGoodWorker.setMargin(new java.awt.Insets(0, 0, 0, 0));
            getContentPane().add(chkUseGoodWorker, java.awt.BorderLayout.CENTER);
            btnStart.setText("Start");
            buttonPanel.add(btnStart);
            btnStop.setText("Stop");
            buttonPanel.add(btnStop);
            getContentPane().add(buttonPanel, java.awt.BorderLayout.SOUTH);
            pack();
        }// </editor-fold>//GEN-END:initComponents
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new MainFrame().setVisible(true);
        // Variables declaration - do not modify//GEN-BEGIN:variables
        private javax.swing.JButton btnStart;
        private javax.swing.JButton btnStop;
        private javax.swing.JPanel buttonPanel;
        private javax.swing.JCheckBox chkUseGoodWorker;
        // End of variables declaration//GEN-END:variables
    // -- The End --

  • Why can caller hear me when i use and ear bud

    Why can't caller hear me when I use an ear bud. I am using the same ear bud that  I used with the Cosmos touch. The Cosmos 3 that I just received worked for awhile with the ear bud but not it's now.  Any suggestions? I'm seriously thinking about going back to my Cosmos Touch, I'm not like this 3. The only thing I like about it is the keyboard.
    Thank You

        clb19,
    We definitely want you to enjoy the new phone as well and it's imperative to get the earbuds working with the phone. Have you tried a different set of earbuds? It it one ear bud specifically? Other than this, do all other sound options work? Is there any damage to the phone?
    AdaS_VZW
    Follow us on Twitter at @VZWSupport 

  • Fonts don't look the same when published...

    why is it when i publish my site to a folder the fonts on some pages do not appear the same as they show in iweb...
    i have 8 pages...
    home page looks fine just as in iweb...
    the remaining pages have a bolder font and doesn't look nice...
    i have checked and double checked every page and all fonts are the same...
    helvetica size 15...
    why is this happening...?
    what can i do...?

    In iWeb click on +Help > iWeb Help+. In the pane that opens you'll see a search bar in the upper right corner. Copy & paste the following into it:
    If text or a shape gets converted to a graphic
    ...and hit Enter. That same phrase should appear in the resulting list of +Help Topics+. Double-click it.
    Follow the steps outlined under +"To identify items that will be converted to graphics when published:"+
    ...Do yellow badges appear on the text you're having problems with? If so, your text is being converted to graphics — to view the fonts least likely to be converted, click the Fonts button in the lower-right corner. In the Font panel under Collections, click Web.
    On the other hand, if yellow badges don't appear then this may apply:
    +"...my text boxes were too small, so a lot of my formatting got messed up when I published the site."+ — Quoted from this old thread:

  • User reviews don't show on websites when i use firefox

    User reviews don't load on websites since the latest Firefox update. They do show when I use IE.

    Hello,
    Are you facing this problem on particular sites??
    Many site issues can be caused by corrupt cookies or cache. In order to try to fix these problems, the first step is to clear both cookies and the cache.
    '''Note:''' This will temporarily log you out of all sites you're logged in to. To clear cache and cookies do the following:
    * Go to Firefox > History > Clear recent history or (if no Firefox button is shown) go to Tools > Clear recent history.
    * Under "Time range to clear", select "Everything".
    * Now, click the arrow next to Details to toggle the Details list active.
    * From the details list, check Cache and Cookies and uncheck everything else.
    * Now click the Clear now button.
    Further information can be found in the [[Clear your cache, history and other personal information in Firefox]] article.

  • Photo Albums & Photos Disappear when publishing using ftp

    Hi,
    I am having trouble with both my iweb sites photos. There is two main problems:
    1. An album that appears normally in iweb is not visable on the published site
    2. An album will have random photos that are missing and replaced with a blank on the published site
    Some things I have tried:
    - I publish via ftp, so I tried publishing to a local folder - The albums and photos work normally
    - I tried republishing with a 3rd party cyperduck - same problem
    - I thought maybe it was therefore a ftp problem. So I logged in to my hostings file manager and check if the files are actually on the server -  but they are..
    - I tried republishing the entire site - same problem
    An example can be seen on the following - the third album is completely missing and if you go into the other albums, there will be random gaps where other photos are missing.
    http://www.gippmed.com/My_Albums/My_Albums.html
    Similar problem on this site, on the USA album, there is two photos missing towards the bottom:
    http://www.lukecainshooting.com/Luke_Cain/Photo_Gallery/Pages/USA.html
    Any help or suggestions would be greatly appreciated.
    Thank you

    Hi Cyclosaurus,
    Thank you for your reply. Sorry to bug you again but can I ask some further questions? Pls excuse my lack of knowledge on these things.
    In relation to your points:
    1) In the ftp publishing settings, public_html is acutal in where it says "site name", where it says "URL" I have http://www.gippmed.com. I was advised to put public_html in "site name" from my hosting. If I put anything else it publishes the entire site to a folder with that name on the server and is not viewable online?
    2) I have removed the spaces in the album page name and will reupload soon. In relation to the image file names, am I correct in saying that iweb is naming them from the captions? Do you really have to use one word captions or use underscores, it looks a little odd? I have read troubleshooting articles about iweb and spaces and it also recommends similar as you are, suggesting that all page names should have underscore instead of spaces. Problem is, if for example I change the page name "About Me" to "About_Me" iweb automatically changes it in the navigation menu and this looks silly to have undescores in the Nav Menu. Is there a way around this?
    Lastly, a new problem that I have never had before:
    Previously, iweb would remember what I had published and only publish new site changes. Now, every time I turn my computer off and on, I open iweb and it doesn't recognise any of the previous publishing, ie it republishes the entire site.
    Thank you again for your help

  • Error when publishing using Muse 2014.3

    I updated Muse to 2014.3 on my pc today. I was working with a current website, which I published this week. I made a few text changes and adjusted the opacity on some elements. Now I cannot publish my website. I get this error message: "Don't know how to generate rendered data for type:type_guid" and I am told to contact the support team alerting them to the steps I took prior to the error. Then I am kicked out of the program. Upon opening Muse again, I find a recovered file. How do I fix this issue? Is there a way for me to revert back to the Muse 2014.2 version? I would like to publish these minor changes to my website.

    stuckonaneyeland In general it's more effective to start a new forum thread for the specific error message you're receiving, rather than reply to a thread that while in the same general area of publish not working, isn't related.
    Go to the Help menu and Sign Out. Quit and relaunch Muse and sign back in. Publishing should work without any errors once this is complete.

  • My computer / iTunes don't recognize my iPod when i use my Nano Dockstation

    I bought a Nano Dockstation for my iPod but when i connect it with my iPod it only charges the battery. It doesn't start up iTunes and my computer gives me a pop up saying: Unknown USB device.
    I already reset my iPod and used other USB ports, that all doensn't work so if you have an idea, please let me know.
    Windows XP

    Place the iOS device in Recovery Mode and then connect to your computer and restore via iTunes. The iPod will be erased.
    iOS: Wrong passcode results in red disabled screen                          
    If recovery mode does not work try DFU mode.                         
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings

  • How can I get Firefox to show videos when I visit websites that have videos? None of the videos play or is visible, even though I can hear the audio. However, I don't have that problem when I use Internet Explorer.

    I'm using a PC with Windows 7 OS.

    Hi Marcos140,
    I would like to help, but is very hard to diagnose with so little information...
    Do you know why you needed the bridge in the first place?
    Is your laptop connecting via wireless or a wired connection?
    Please try this:
    #Click start
    #Type cmd
    # Push Enter
    #A black box will open
    # type in "ipconfig /all"
    # Screenshot the output
    # type "ping google.com"
    # Screenshot
    If you can post the output of those commands it will help.
    Thanks,
    Curtis

  • How do I stop Firefox from creating untitled web pages when I try to send email from a web page. The only way I have found is to turn the computor off and then reboot. I don't have this problem when using Internet Explorer

    Every time I click on a web site that has an email option the browser starts making untitled web pages and never stops unless I turn the computer off. It is very frustrating to not be able to use an email option when offered by a web site. The only way I can send email messages on the Firefox browser is to go into my hotmail acct. and copy and paste the addresses. I don't have this problem when I use the Internet Explorer browser.

    See [[Firefox keeps opening many tabs or windows]]

  • How to invoke Bpel process  from java using 'bpel process WSDL'

    I want to call bpel process from java using bpel wsdl.
    could any one point me to any url/sample.
    Thanks
    Nagajyothy

    Hi Seshagiri,
    Thanks for providing links and initial steps to create web service proxy(using Jdeveloper 11g).
    I created a web service proxy.
    provided the needed inputs.
    when I ran the client app, bpel process(has a human task) got invoked but faulted with exception as below
    Operation 'initiateTask' failed with exception 'EJB Exception: : java.lang.ExceptionInInitializerError[[
         at oracle.tip.pc.services.common.ServiceFactory.getAuthorizationServiceInstance(ServiceFactory.java:147)
         at oracle.bpel.services.workflow.task.impl.TaskService.initiateTask(TaskService.java:1159)
         at oracle.bpel.services.workflow.task.impl.TaskService.initiateTask(TaskService.java:502)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
    please help me in solving the above problem.
    Thanks
    Nagajyothy

  • Scheduling BPEL Process in 11g using native SOA Suite functionatliy

    I have spent a significant amount of time reviewing documentation and the forums and have been unable to find a definitive answer on the ability to schedule a BPEL process in SOA Suite 11g.
    A similar question was asked here with no response:
    BPEL(SOA11G) and Quartz
    In SOA Suite 10.1.3.x it is discussed frequently:
    http://www.oracle.com/technology/tech/soa/soa-suite-best-practices/soa_best_practices_1013x_drop1.pdf
    Re: BPEL Adapters & Scheduling
    It appeared to be an actual feature in one of the technology previews:
    http://biemond.blogspot.com/2008/01/scheduling-processes-in-soa-suite-11g.html
    Can anyone provide an definitive answer on whether a BPEL process can be scheduled using functionality native to SOA Suite 11g. I understand there are external workarounds such as calling BPEL process from DBMS_JOB, using external scheduling framework etc. I am interested in solutions which are native to the SOA Suite itself if there is such a solution.
    If there is no definitive answer I will open a support case and post the results here for the benefit of the group.

    Hi-
    You can refer to the below link.
    http://darwin-it.blogspot.com/2008/01/how-to-create-bpel-job-scheduler.html
    I have not personally tried but I think it should work.
    PLease let us know how it goes.
    Thanks,
    Dibya

  • Calling an AJAX process when before IR refresh

    Hello All,
    I have a situation here :
    Run a application process that will set some parameters.
    I would like to run the same process before an IR refresh,
    I can create an on demand process but how to call this process in the javascript before the IR refresh ?
    Thanks,
    Dippy

    Hello Jari,
    I have APEX 4 and I did create a dynamic action & slected Before Refresh of IR region and put in my plsql code.
    So will this code be called every time the IR report is refreshed ?
    Thanks,
    Dippy

  • Need to sinc my iphone 4 never done it before and when I plug it in to the laptop it tries to sinc to my dad's old long gone iphone?

    I need to sinc my iphone 4 that I bought in the summer of 2011. I've never done it before and when I plug it in to the laptop it tries to sinc to my dad's old long gone iphone?
    This laptop was used by him when he had a iphone a year or so ago but he has since changed to an android phone.
    This is the only laptop we have and he has no use for the itunes or anything iphone related now so how do I get Itunes to forget his phone and let me connect mine so that everything on my iphone can backed up and so I may proceed with all the updates out there to bring it current....while still losing none of my stuff.
    it was only plugged in for a second and now my ipone setting about page says "Danny's phone" which is what his used to be called but all my stuff is still here...???

    Hey joshuafromisr,
    If you resintall iTunes, it should fix the issue. The following document will go over how to remove iTunes fully and then reinstall. Depending on what version of Windows you're running you'll either follow the directions here:
    Removing and Reinstalling iTunes, QuickTime, and other software components for Windows XP
    http://support.apple.com/kb/HT1925
    or here:
    Removing and reinstalling iTunes, QuickTime, and other software components for Windows Vista or Windows 7
    http://support.apple.com/kb/HT1923
    Best,
    David

  • Slideshows don't work when published to .mac

    After upgrading to iLife '08, the slideshows on my photo pages published from iWeb to .mac no longer work. They worked fine before. When I post to my web gallery directly from iPhoto, the slideshow works fine. I have checked to make sure the slideshow is enabled, and republished all of my pages. Now all of them don't work. Before that, only the new ones didn't work.

    Thanks for your response, answered below:
    If you build your site in iWeb '06 and converted it to '08 I would rebuild the photo pages from scratch. ANSWER The contents of the podcast track in '08 were replaced, not rebuilt
    Do you still have an "iWeb" folder in Finder/Go/iDisk/My iDisk/Web/Sites? ANSWER: Yes, but there is nothing in it
    THE CURRENT SITUATION is that the website loads, but the podcast picture doesn't appear, just a Quicktime logo with a ? in it. The sound tracks still play but no images appear.
    Asked my husband to load the page on his PC, same thing happens ie the Quicktime logo with a ? appears.

Maybe you are looking for

  • Leopard in the Enterprise

    I'm partner in a small company with 7 employees. We are all Mac fans and would like to be able to work collaboratively with our Macs. I originally came from a Windows work-environment where I got to know Microsoft Exchange and Microsoft SharePoint. B

  • Error While Adding Service A\P Invoice

    Hi Expert, I am getting an Error while adding the service A\P invoice The error is: System.NullRefernce Exception :- Object Reference not set to an instance of an object. At CXS_TDS_BAL.clsAPInvoice I also Restarted my  TDS Addon but still getting sa

  • Inserting image in a wiki page

    Hi All, How to add image in a wiki page. I want to insert an image in between the contents of the wiki page. thanks & regards, Manoj

  • 1.1.3 error- Network connection timed out

    Anyone else get this problem? And if so what should I do about it? Thanks

  • Windows keeps on asking for my user credentials

    Hi. As per subject, I keep on getting prompted to enter my user credentials whenever I open a mapped drive (which has been mapped before with the same credentials) or when I open the SharePoint site and also when I check out and edit a document from