For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!
Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.
import java.text.SimpleDateFormat; import java.util.Date; import javax.swing.SwingWorker; public class SwingWorkerTest { public static void main(String[] args) { for (int i = 1; i <= 30; i++) { new Worker(i).execute(); } } } class Worker extends SwingWorker { private int id; public Worker(int id) { this.id = id; } @Override protected Object doInBackground() { System.out.println(new SimpleDateFormat("HH-mm-ss:").format(new Date(System.currentTimeMillis())) + " started worker no." + id); try { Thread.sleep(5000); // Do nothing for 5 seconds } catch (InterruptedException e) { ; } return null; } }
20-42-01: started worker no.10 20-42-01: started worker no.9 20-42-01: started worker no.5 20-42-01: started worker no.3 20-42-01: started worker no.6 20-42-01: started worker no.7 20-42-01: started worker no.2 20-42-01: started worker no.1 20-42-01: started worker no.8 20-42-01: started worker no.4 20-42-06: started worker no.12 20-42-06: started worker no.11 20-42-06: started worker no.13 20-42-06: started worker no.14 20-42-06: started worker no.15 20-42-06: started worker no.16 20-42-06: started worker no.17 20-42-06: started worker no.18 20-42-06: started worker no.19 20-42-06: started worker no.20 20-42-11: started worker no.21 20-42-11: started worker no.22 20-42-11: started worker no.23 20-42-11: started worker no.24 20-42-11: started worker no.25 20-42-11: started worker no.26 20-42-11: started worker no.27 20-42-11: started worker no.28 20-42-11: started worker no.29 20-42-11: started worker no.30