30 lines
734 B
Java
30 lines
734 B
Java
public class MultipleThread implements Runnable {
|
|
String task;
|
|
MultipleThread(String task){
|
|
this.task = task;
|
|
}
|
|
public void run(){
|
|
for(int i = 0; i<= 5; i++){
|
|
System.out.println(task+ ":" + i);
|
|
try {
|
|
Thread.sleep(400);
|
|
} catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
public static void main(String[] args){
|
|
Thread nThread = Thread.currentThread();
|
|
System.out.println("Name of thread : "+ nThread);
|
|
|
|
MultipleThread mt = new MultipleThread("hello");
|
|
Thread t1 = new Thread(mt);
|
|
Thread t2 = new Thread(mt);
|
|
Thread t3 = new Thread(mt);
|
|
t1.start();
|
|
t2.start();
|
|
t3.start();
|
|
int count = Thread.activeCount();
|
|
System.out.println("No. of active threads: " +count);
|
|
}
|
|
} |