Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

thread in java


public class MyThread extends Thread {
    private final String name;

    public MyThread(String name) {
        this.name = name;
    }

    public void run() {
        try {
            for (; ; ) {
                System.out.println(name);
                Thread.sleep(1000);
            }
        } catch (InterruptedException e) {
            System.out.println("sleep interrupted");
        }
    }

    public static void main(String[] args) {
        Thread t1 = new MyThread("First Thread");
        Thread t2 = new MyThread("Second Thread");
        t1.start();
        t2.start();
    }
}

Source by devarama.com #
 
PREVIOUS NEXT
Tagged: #thread #java
ADD COMMENT
Topic
Name
1+4 =