Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Sales1 implements Runnable {
- Thread t;
- boolean suspended = false;
- Sales1()
- {
- t=new Thread(this,"Personname");
- t.start();
- }
- @Override
- public void run() {
- // TODO Auto-generated method stub
- try {
- // Let the thread sleep for a while.
- Thread.sleep(300);
- synchronized(this) {
- while(suspended) {
- wait();
- System.out.println("persons");
- }
- }
- }
- } catch (InterruptedException e) {
- System.out.println("Thread interrupted.");
- }
- }
- void suspend() {
- suspended = true;
- }
- synchronized void resume() {
- suspended = false;
- notify();
- }
- }
- class Day1 implements Runnable {
- Thread t1;
- Sales1 obj;
- String day[]={"Sunday","Monday","Tueasday","Wednesday","Thursday","Friday","Saturday"};
- Day1()
- {
- t1=new Thread(this,"day");
- obj=new Sales1();
- //Thread t2=new Thread(obj);
- t1.start();
- //t2.start();
- }
- @Override
- public void run() {
- // TODO Auto-generated method stub
- for(int i=0;i<31;i++)
- {
- int j=i%7;
- System.out.println(day[j]);
- if(day[j]=="Sunday")
- {
- obj.suspend();
- }
- else if(day[j]=="Wednesday")
- {
- obj.resume();
- }
- }
- }
- }
- public class Salesman {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- //SynThreads1 q=new SynThreads1();
- Day1 d=new Day1();
- //new SalesPersons();
- //d.start();
- }
- }
Add Comment
Please, Sign In to add comment