package com.evs.objava33.class14;
public class TryThread extends Thread {
private String firstName;
private String lastName;
private Long delay;
public TryThread(String firstName, String lastName, Long delay) {
this.firstName = firstName;
this.lastName = lastName;
this.delay = delay;
}
public void run() {
while (true) {
System.out.println(firstName);
try {
sleep(delay);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(lastName);
}
}
public static void main(String[] args) {
Thread first = new TryThread("Asif", "Sajjad", 2000L);
Thread second = new TryThread("Shahzad", "Masud", 3000L);
Thread third = new TryThread("Kamran", "Ahmad", 5000L);
first.start();
second.start();
third.start();
}
}
No comments:
Post a Comment