1. Create a class of SalesPersons as a thread that will display five salespersons names.
2. Create a class as Days as other Thread that has an array of seven days.
3. Call the instance of SalesPersons in Days and start both the
threads
4. suspend SalesPersons on Sunday and resume on Wednesday
Note: use suspend, resume methods from the thread
class Days extends Thread {
private String[] days = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
public void Display() {
SalesPersons Sp = new SalesPersons();
Sp.start();
for (String D : days) {
System.out.println(D);
try {
sleep(800);
} catch (InterruptedException m) {
m.printStackTrace();
}
if(D=="Sunday"){
System.out.println("Suspending");
Sp.suspend();
try {
sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (D=="Wednesday") {
System.out.println("Resuming");
Sp.resume();
}
}
}
}
class SalesPersons extends Thread {
private String[] names = {"Jack", "Ben", "Mary", "Chris", "Ria"};
public void Display() {
for (String N : names) {
System.out.println(N);
try {
sleep(500);
} catch (InterruptedException m) {
m.printStackTrace();
}
}
}
}
public class Main {
public static void main(String[] args) {
Days d = new Days();
Thread q = new Thread(d);
q.start();
}
}
Comments
Leave a comment