Commit 50c2be8a authored by Crio.GitLab's avatar Crio.GitLab 💬
Browse files

Update ThreadJoinExample.java

parent 92a1a779
package com.crio.session3.activity1;
public class ThreadJoinExample {
public static void main(String[] args) throws InterruptedException {
System.out.println("main thread started execution. Current thread name : " + Thread.currentThread().getName());
PrintNumbers t1 = new PrintNumbers(1, 10);
PrintNumbers t2 = new PrintNumbers(11, 20);
PrintNumbers t3 = new PrintNumbers(21, 30);
t1.start();
t1.join();
t2.start();
t2.join();
t3.start();
t3.join();
System.out.println("All threads completed excution.");
System.out.println(Thread.currentThread().getName() + " complete execution");
}
}
class PrintNumbers extends Thread {
private int start;
private int end;
public PrintNumbers(int start, int end) {
this.start = start;
this.end = end;
}
@Override
public void run() {
for (int i = start; i <= end; i++) {
System.out.println(Thread.currentThread().getName() + " - " + i);
}
System.out.println(Thread.currentThread().getName() + " thread execution completed.");
}
}
package com.crio.session3.activity1;
public class ThreadJoinExample {
public static void main(String[] args) throws InterruptedException {
System.out.println("main thread started execution. Current thread name : " + Thread.currentThread().getName());
PrintNumbers t1 = new PrintNumbers(1, 10);
PrintNumbers t2 = new PrintNumbers(11, 20);
PrintNumbers t3 = new PrintNumbers(21, 30);
t1.start();
//t1.join();
t2.start();
//t2.join();
t3.start();
//t3.join();
System.out.println("All threads completed excution.");
System.out.println(Thread.currentThread().getName() + " complete execution");
}
}
class PrintNumbers extends Thread {
private int start;
private int end;
public PrintNumbers(int start, int end) {
this.start = start;
this.end = end;
}
@Override
public void run() {
for (int i = start; i <= end; i++) {
System.out.println(Thread.currentThread().getName() + " - " + i);
}
System.out.println(Thread.currentThread().getName() + " thread execution completed.");
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment