Java examples for Thread:Thread Operation
Creating a Thread
class BasicThread1 extends Thread { // This method is called when the thread runs public void run() { }//w ww.j a v a2 s.c om } class BasicThread2 implements Runnable { // This method is called when the thread runs public void run() { } } public class Main { public static void main(String[] args) { // Create and start the thread Thread thread = new BasicThread1(); thread.start(); // Create the object with the run() method Runnable runnable = new BasicThread2(); // Create the thread supplying it with the runnable object thread = new Thread(runnable); // Start the thread thread.start(); } }