Skip to content

Instantly share code, notes, and snippets.

@AtomicBlom
Last active November 7, 2015 13:04
Show Gist options
  • Save AtomicBlom/9e0a785e6715403c6462 to your computer and use it in GitHub Desktop.
Save AtomicBlom/9e0a785e6715403c6462 to your computer and use it in GitHub Desktop.
//Keep track of the threads doing work
Thread[] threads = new Thread[10];
//Create 10 threads
for (int i = 0; i < 10; i++) {
//You need to create a Runnable class instance (anonymous class works too)
threads[i] = new Thread(new BluSunrizeSuperItemCheckerThing());
//Start the thread processing immediately
threads[i].start();
}
//iterate over each thread individually
for (final Thread thread : threads)
{
try {
//Wait for this thread to finish. If it's already finished, this will proceed immediately.
thread.join();
} catch (InterruptedException e)
{
e.printStackTrace();
}
}
//This line will only execute once all 10 threads have finished
System.out.print("done!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment