Java Scrap Book  

Java Scrap Book > Java Thread > Create Java Thread

Create Java Thread - Extends Thread Class

A Thread in Java defines by extending the Thread class and overrring the run() methods.

Thread example

import  java.io.IOException;
class ThreadExample extendsThread {
  public ThreadExample(String name) {
    this.name = name;
    }
public void run(){
    try{
    while (true) {
System.out.print(name);
}
} catch (InterruptedException e) {
System.out.println(e);
}
}
private String name;
}
public class ThreadDemo {

public static void main(String[] args) {
Thread a = new ThreadExample("java");
Thread b = new ThreadExample("scrap");
a.start();
b.start();
}
}


Reference:
Create Thread by extending Thread class

Copyright © 2013-2017

javascrapbook.com is a computer science content service should not be treated as the publisher or speaker of any information provided by another Computer Science content provider.

Contact email: help@javascrapbook.com