Java - Runnable

Java Conceptuel Diagram

About

A Runnable is a configuration object that define the code that will run inside threads. See example

Example

  • You define the code to be run in the method, run
  • You pass the Runnable object to the Thread constructor.
  • And you start the thread
public class HelloRunnable implements Runnable {

    public void run() {
        System.out.println("Hello from a thread!");
    }

    public static void main(String args[]) {
        (new Thread(new HelloRunnable())).start();
    }

}





Discover More
Java Conceptuel Diagram
Java Concurrency - Executor (Thread manager)

An executor is a thread management module (thread creation and management). java.util.concurrent provides two executor interfaces: java/util/concurrent/ExecutorExecutor is a simple standardized...
Thread Java Mission Control
Java Concurrency - Thread

Every application has at least one thread . From the application programmer's point of view, you start with just one thread, called the main thread. From this thread, you can start other threads. ...



Share this page:
Follow us:
Task Runner