MyThread.java 485 Bytes
Newer Older
Luca Arrotta's avatar
Luca Arrotta committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
package join;

import java.util.Random;

public class MyThread extends Thread {
    private Random rnd;

    MyThread(Random r) {
        rnd = r;
    }

    public void run() {
        int seconds = rnd.nextInt(10) + 1;

        System.out.println("A thread started!");

        try
        {
            Thread.sleep(seconds * 1000);
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }

        System.out.println("A thread died!");

    }

}