O'Reilly logo

Hands-On High Performance with Spring 5 by Dinesh Radadiya, Prashant Goswami, Pritesh Shah, Subhash Shah, Chintan Mehta

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

ThreadFactory

The ThreadFactory interface is used to create a new thread on demand and also helps us to eliminate lots of boilerplate code for creating threads.

The following example shows how we can use the ThreadFactory interface to create new threads:

public class ThreadFactoryExample implements ThreadFactory {  private static final Logger LOGGER =     Logger.getLogger(ThreadFactoryExample.class);  public static void main(String[] args) {    ThreadFactoryExample factory = new ThreadFactoryExample();    Runnable task = new Runnable() {      public void run() {        LOGGER.info(Thread.currentThread().getName());      }    };    for (int i = 0; i < 5; i++) {      Thread t = factory.newThread(task);      t.start();    }  }  @Override  public Thread newThread(Runnable r) { Thread t = new ...

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