Concurrency – Runnable Interface in Java


Implementing Runnable is a way to create threads by defining a run method.

Source Code

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

    public static void main(String[] args) {
        Thread thread = new Thread(new HelloRunnable());
        thread.start();
    }
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments