Latest News

 










Thread constructors and names

Previous slide Next slide Back to first slide View graphic version


Thread constructors and names


 
My other sites

Latest News

 










Thread constructors and names

  • There are four basic constructors; their arguments can be:

    • A name (String) for the Thread (default null).
      • Should be unique, used for debugging etc.
    • An object (Runnable) to call a run() method in.
      • Default is this object

    class ThreadExample implements Runnable {
    public ThreadExample {
    Thread t1 = new Thread();
    Thread t2 = new Thread("sun");
    Thread t3 = new Thread(this);
    Thread t4 = new Thread(this, "t4");
    String n2 = getName();
    t3.setName("t3");
    }
    public void run() { }
    }

Previous slide Next slide Back to first slide View graphic version