Java - Runnable


A Runnable is a configuration object that define the code that will run inside threads. See 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();


Powered by ComboStrap