O'Reilly logo

Java 9 Concurrency Cookbook - Second Edition by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

Follow these steps to implement the example:

  1. Create a class called DataSourcesLoader and specify that it implements the Runnable interface:
        public class DataSourcesLoader implements Runnable {
  1. Implement the run() method. It writes a message to indicate that it starts its execution, sleeps for 4 seconds, and writes another message to indicate that it ends its execution:
        @Override         public void run() {           System.out.printf("Beginning data sources loading: %s\n",                            new Date());           try {             TimeUnit.SECONDS.sleep(4);           } catch (InterruptedException e) {             e.printStackTrace();           }           
          System.out.printf("Data sources loading has finished: %s\n",                            new Date());         }
  1. Create a class called NetworkConnectionsLoader and specify that it implements ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required