Skip to content

Instantly share code, notes, and snippets.

@chathurangat
Last active December 3, 2017 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chathurangat/e02a619e27d131720211ffd9c9d300f9 to your computer and use it in GitHub Desktop.
Save chathurangat/e02a619e27d131720211ffd9c9d300f9 to your computer and use it in GitHub Desktop.
public class Application
{
public static void main(String[] args) throws Exception
{
System.out.println(" main thread has started ");
CountDownLatch countDownLatch = new CountDownLatch(4);
WorkerThread workerThread1 = new WorkerThread("thread1", countDownLatch);
WorkerThread workerThread2 = new WorkerThread("thread2", countDownLatch);
WorkerThread workerThread3 = new WorkerThread("thread3", countDownLatch);
WorkerThread workerThread4 = new WorkerThread("thread4", countDownLatch);
new Thread(workerThread1).start();
new Thread(workerThread2).start();
new Thread(workerThread3).start();
new Thread(workerThread4).start();
System.out.println(" all the worker threads have been started. next calling await() method ");
countDownLatch.await();
System.out.println(" Resume the main thread after executing all worker threads");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment