SwingWorker don't start immediately - question

Given: two SwingWorkers (SW). I want them BOTH to start working immediately upon execute(). However, it seems that the second SW waits for the first SW to complete. Below is a working example. When you run it, you will see that it pauses ten seconds between debug print statements FIRST and SECOND. Why does it pause? Should not FIRST and SECOND appear nearly simultaneously? How do I make both SW start immediately? Thanks.
import javax.swing.SwingWorker;
public class Test {
private void test() {
new SwingWorker<Object, Void>()
@Override
protected Object doInBackground() throws Exception
System.out.println("FIRST");
System.out.flush();
Thread.sleep(10000);
return null;
@Override
protected void done()
}.execute();
new SwingWorker<Object, Void>()
@Override
protected Object doInBackground() throws Exception
System.out.println("SECOND");
System.out.flush();
return null;
@Override
protected void done()
}.execute();          
public static void main(String[] args) {
System.out.println("START");
System.out.flush();
new Test().test();
try {
Thread.sleep(20000);
catch(InterruptedException e) {
System.out.println("STOP");
}

Turns out I found a bug: http://forums.sun.com/thread.jspa?threadID=5434659. This works great:
import javax.swing.SwingWorker;
import java.util.concurrent.Executors;
import java.util.concurrent.Executor;
public class Test {
    private void test() {
     Executor executor = Executors.newCachedThreadPool();
     executor.execute(
     new SwingWorker<Object, Void>()
         @Override
         protected Object doInBackground() throws Exception
          System.out.println("FIRST");
          System.out.flush();
          Thread.sleep(10000);
          return null;
         @Override
         protected void done()
     executor.execute(
     new SwingWorker<Object, Void>()
          @Override
          protected Object doInBackground() throws Exception
               System.out.println("SECOND");
               System.out.flush();
               // Thread.sleep(10000);
               return null;
          @Override
          protected void done()
    public static void main(String[] args) {
     System.out.println("START");
     System.out.flush();
     new Test().test();
     try {
         Thread.sleep(20000);
     catch(InterruptedException e) {
     System.out.println("STOP");
}

Similar Messages

  • Hey Adobe, stop asking whether I want you to install updates automatically.  I DON'T.  Some programs I run crash if you jump in there and start asking questions.

    Hey Adobe, stop asking whether I want you to install updates automatically.  I DON'T.  Some programs I run crash if you jump in there and start asking questions.

    You can set your preferences to not prompt you for updates, either having them done without asking, or relying on yourself to manage them

  • How make my internet open/start immediately when turn on computer?

    How make my internet open/start immediately when turn on computer?
    ps: using FFox, if it makes any difference.
    Don't think I wont't thank you, Cuz
    I will.

    Thank you verry much, HipHop.
    FFox has long been on my doc.
    I clicked it and it shows i have instructed it to 'Open at Login'.
    Same thing with Apple/Prefs/Accounts/Login items where it shows i have instructed it, and also Safari now, to Open at Login (and not checked to Hide).
    But still it never opens.
    Safari opens at login. But not Firefox.
    And it's not that the 2 are conflicting, cuz
    I had this problem with FFox long time when started this question;
    and I only just the other day added Safari to open at login cuz I was advised to try it just to see if Saf wd open on Login.
    I did contact my isp, dslextreme, but they couldn't help me other than the advice I've already gotten here, said not their specialty, that I should ask Apple or FFox (I'll try that).
    Thanks again, everybody.
    I still dream of what I will do with all the time I will save someday by not having to actually click on the FFox icon to start it. Call me a dreamer, but I'm not the only one (or am i?)
    ps: Are you really hip hop?

  • Since I have changed from Windows 7 to Windows 8.1, I have not been able to start up Photoshop Elements 9! or Premiere Elements 9! The menu starts up allright, but the programs don't start when I press any buttons. How do I fix this problem?

    Since I have changed from Windows 7 to Windows 8.1, I have not been able to start up Photoshop Elements 9! or Premiere Elements 9! The menu starts up alright, but the programs don't start when I press any buttons. How do I fix this problem?

    If Layers is greyed out it possibly means that you are in Quick Mode. Select 'Expert' and all the options should become available.
    Try permanently associating psd files with C:\Program Files (x86)\Adobe\Photoshop Elements 12\PhotoshopElementsEditor.exe and see if that fixes the issue. Instructions here - http://windows.microsoft.com/en-gb/windows-8/choose-programs-windows-uses-default.
    Cheers,
    Neale
    Insanity is hereditary, you get it from your children
    If this post or another user's post resolves the original issue, please mark the posts as correct and/or helpful accordingly. This helps other users with similar trouble get answers to their questions quicker. Thanks.

  • PSE 12 don't start when connecting camera

    Photodownlaoder don't start when connecting camera or sd card. Even when its started manually, the media won't get imported to harddisk.
    I'm using windows 8. Camera is tested on several computers with differnet fot software and funtions perfect. PSE 12 causes me trouble...

    One more information:
    this is my second iPhone that I use on the mac. I gave my first phone back to the dealer because
    of some cracks in the housing and I activate this second phone.
    Maybe this is the reason, that iTunes doesn´t react ?
    Can I control or delete the first iPhone (or must I do this ?)
    Where can I look after all my confirmed iPhones and iPods on my iTunes ?
    Many questions; I know....

  • Itunes don't start (First installation)

    Hello,
    French user in enterprise ... we have a 60 iPhones and we want to install Itunes on PC of the User.
    PC are under Windows 7 Prof. and in a domain.
    Installation on the User domain account = OK but launch Itunes =  50% OK and Other KO (Itunes never start)
    if KO : under session domain admin = itunes start OK ; under session Local admin = itunes start Ok
    We declare the domain User as Admin local and iTunes Dont't Start (again)
    When I tell don't start, no msg of erreur, no process in the process list in the monitor.
    We try to install the Setup (x64) as administrator (right clic) => launch setup = install OK
    Same bug when we want to start itunes since the user domain account.
    We can't change the user account.
    We 're thinking there is authorization problem but we can't find where.
    All we found on forum and else aren't solve the bug.
    A fix ? A link ? to help use ... we have 10 PC whith the start bug and we are near the suicid

    Resolve
    We found bad directory redirection for "documents" on domain GPO (redirection on a old server).
    We :
    * change the bad value in the GPO.
    * restart the PC and login with the domain user account. GPO apply correctly.
    * launch iTunes and ... miracle ... Itunes Start correctly.
    No thanks to Apple, because:
    * no error message,
    * no information for bad directory to create iTunes directory in "my music",
    * no question to write/declare a new location cause of error create iTunes directory for the media bank
    * just close Itunes on the error without information and 6 hours loose in search for the cause.
    Thanks to fromsouth to the search way.
    See you soon

  • When i do the download of adobe reader 11 there is only a black window and it don't start

    when i do the download of adobe reader 11 there is only a black window and it don't start
    excuse for my bad english but i'm italian

    Please don't post the same question multiple times!

  • After IOS 8 upgrade IPad 2 don't start

    Hi,
    After IOS 8 upgrade my IPad 2 don't start and just show this screen and nothing works.

    My ipad2 is having the same problem.  I can get it to start up by plugging the charger in.  I can then unplug it and it is working - but very slow and prone to randomly shutting things down.

  • After add (in a wrong way)  a new disk in ASM, cluster don´t start

    Hi,
    Environment:
    Oracle RAC 10gR2
    2 nodes windows 2003 advanced server (node1 called "database1" and node2 called "database2").
    ASM
    san storage
    Case:
    My client has tried to add a new disk (in a environment san) in ASM with the next steps:
    1. database1 and database2 are up.
    2. instance ASM1 from database is up and instance ASM2 from database2 is down (I don´t know why¿¿¿¿¿¿¿??????????).
    3. add a new disc from san storage to instance ASM1. At the end, a lot of errors show in screen due to  instance ASM2 was down.
    4. client tried to up +ASM2 and then , all the cluster crashed.
    5. reboot boths nodes database1 and database2 , and Windows 2003 Server don´t start well (hung up, due to services from oracle cluster are "automatically start"-
    6. disable oracle services in "not automatically start" and windows 2003 server start well.
    7. now oracle rac don´t start, ASM don start, instances don´t start ....
    what can I do? any idea?
    Regards.
    Laura

    Did you try to bring the U1 and it's associated ASM instance up while the other node is shutdown? Are you using Oracle clusterware?

  • Reports Multi-tier server from Dev 2000:v 1.6.1 don't start on solaris 8

    Reports Multi-tier server from Oracle Developer 2000:version 1.6.1 don't start on Sun Sparc Solaris 8, it writes:
    Segmentation Fault (core dumped). What i have to do?

    Reports Multi-tier server from Oracle Developer 2000:version 1.6.1 don't start on Sun Sparc Solaris 8, it writes:
    Segmentation Fault (core dumped). What i have to do?

  • WEB.SHOW_DOCUMENT don´t start Firefox 3.5

    Hi @all,
    I want to call a report through Forms per web.show_document but Firefox don´t start. The URL is correct (I´ve tested it). I tried also to disable the Popup-Blocker but this didn´t solve the problem, too.
    I call the fmx with a JNLP File.
    There is no other browser installed on my system.
    Are there any other settings in the browser (or maybe in the OS (WinXPPro SP3)) which could be responsible for this problem.
    Thanks for your suggestions.
    Thomas

    Hi,
    no, I run my forms in a Java Virtual Machine ( I start it with a JNLP-File) not directly in a browser. Adobe 9 is installed. In "showmyjobs" there are no report jobs listed, because the browser don´t start and try to open the report. When I copy manually the URL (which should call the report) from web.show_document into the browser the report starts. There is no problem in calling the report.
    The problem is that web.show_document don´t start the browser or if the browser is already open a new tab to call the URL which I have written in web.show_document.
    e.g.
    web.show_document('http://www.google.de'. '_blank') should call google in a new browser tab or, if the browser is not opened already, in a new browser. But in my case the browser don´t start or don´t start a new tab page. This problem occurs in IE and in Firefox.
    I use JDK 6 Update 16 and Forms works fine with that version.
    I´ll try it tomorrow with another Java Version but I don´t think that this solve the problem.
    Thomas

  • Oracle 8.1.7 on windows 2000 don't start automatic :(

    Why Oracle 8.1.7 don't start automatic on windows 2000 :(
    Services
    Oracleora3Agent
    Oracleora3DataGatherer
    Oracleora3TNSListener
    OracleServiceORA3
    are started autamatic. (ora3 is SID)
    if I execute command "startup open" in Server Manager (svrmgrl), then DataBase started

    I've got the same problem.
    However, I've found that if I set the OracleServiceXXX startup to manual, If I then issue a net start statement it works OK.
    i.e NET START OracleServiceXXX
    Hope this helps.

  • Downloaded songs don't start at the beginning of the song, why?

    the songs i bought from itunes don't start at the beginning of the song,  it's just the preview clip.

    Been having the same problems myself. And I don't know about you but sometimes it'll take a while to get it to actually play the first song.

  • Java Apps don't start automaticaly after system restart

    Hi,
    Since a few days ago when restarting Java application servers of SAP
    Portal, the applications deployed don't start for itselfs.
    When starting the instance, the memory stops to increase at 500mb. The
    only way to start the applications is by the manual way in:
    Server -> Services -> Deploy -> Runtime -> Application -> Start
    Application.
    After starting the applications manually the instance starts fine.
    I already increased some values in global configuration:
    From:
    InitialThreadCount = 40
    MaxThreadCount = 150
    MinThreadCount = 40
    To:
    InitialThreadCount = 80
    MaxThreadCount = 200
    MinThreadCount = 80
    After the restart the applications are not starting automaticaly yet.
    I have 4 instances. The first two instances are starting fine, but the problem is happening with the other 2 instances.
    Is there any reason for this type of behavior?
    Thanks for the help
    Pedro Nunes

    Hello Vyara,
    thanks for your reply.
    This kind of problem happens since 3 weeks ago and the stack of this system (SP09) remain unchangeble since 07.04.2008.
    The strange behavior is that the Server 1 and 2 are starting all the apps fine, but this problem is only happens in server 3 and 4.
    Can you help please?
    Thanks

  • How do I repeat a function that starts immediately?

    Hi,
    I am using a Timer function to repeat a function however the function only begins (and repeats) after the period set eg. 5 seconds not immediately.
    Here is an example of the code:
    var myTimer:Timer = new Timer(2000,8);
    myTimer.addEventListener(TimerEvent.TIMER, timerListener);
    function timerListener (e:TimerEvent):void{
    trace("Timer is Triggered");
    myTimer.start();
    Is there any way to make the function start immediately then repeat?
    Thanks
    Chris

    after timer.start()
    add
    myTimer.dispatchEvent(new TimerEvent(TimerEvent.TIMER));
    this will trigger your function immediately

Maybe you are looking for

  • How to update my phone is my 3g plan

    dear sir i don't have wifi network but i am use 3g data so how can update ios 8.2 on my phone

  • Photos from computer to TV

    I have photographs on my computer and I would like to have them shown on my TV.Could you tell me how this is done?            Thanks

  • CM 5.1 devicelistx

    I used the devicelistx https://CCMIP/ccmadmin/reports/devicelistx.asp page in CM 4.2 for get the status on real time from devices Now I use the CM 5.1 but in this version devicelistx page doesnt exist. How can i know now the status on real time from

  • Error During invoice

    Dear All While doing invoice system is telling cost centre not belongs bussiness area 9012.I checked the assignment in OKENN it is found to be OK. Regards Srinivasan.P Edited by: srinivasan ponnurangam on Apr 25, 2009 10:40 AM

  • HT201413 error 21 linked to battery failure

    Hi I have been having a problem with My Iphone 4. It started 2 days ago when it had 10% battery left, I was timing a sports game and when i went to check the time 5 minutes later and the phone had shut down. I thought it was down to the fact it had n