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

Creating threads

Threads are objects in the Java language. They can be created using the following mechanisms:

  • Create a class that implements the Runnable interface
  • Create a class that extends the Thread class

There are two ways to create a Runnable object. The first way is to create a class that implements the Runnable interface as follows:

public class ThreadExample {  public static void main(String[] args) {    Thread t = new Thread(new MyThread());    t.start();  }}class MyThread implements Runnable {  private static final Logger LOGGER =       Logger.getLogger(MyThread.class);  public void run() {    //perform some task    LOGGER.info("Hello from thread...");  }}

Before Java 8, we only had this way to create a Runnable object. But since Java 8, we can create ...

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