Guest User

Untitled

a guest
Jun 19th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. class Sales1 implements Runnable {
  2.  
  3. Thread t;
  4. boolean suspended = false;
  5. Sales1()
  6. {
  7. t=new Thread(this,"Personname");
  8. t.start();
  9. }
  10. @Override
  11. public void run() {
  12. // TODO Auto-generated method stub
  13. try {
  14. // Let the thread sleep for a while.
  15. Thread.sleep(300);
  16. synchronized(this) {
  17. while(suspended) {
  18. wait();
  19. System.out.println("persons");
  20. }
  21. }
  22. }
  23. } catch (InterruptedException e) {
  24. System.out.println("Thread interrupted.");
  25. }
  26.  
  27.  
  28. }
  29. void suspend() {
  30. suspended = true;
  31. }
  32.  
  33. synchronized void resume() {
  34. suspended = false;
  35. notify();
  36. }
  37.  
  38. }
  39. class Day1 implements Runnable {
  40.  
  41. Thread t1;
  42. Sales1 obj;
  43. String day[]={"Sunday","Monday","Tueasday","Wednesday","Thursday","Friday","Saturday"};
  44. Day1()
  45. {
  46. t1=new Thread(this,"day");
  47. obj=new Sales1();
  48. //Thread t2=new Thread(obj);
  49. t1.start();
  50. //t2.start();
  51.  
  52. }
  53. @Override
  54. public void run() {
  55. // TODO Auto-generated method stub
  56. for(int i=0;i<31;i++)
  57. {
  58. int j=i%7;
  59. System.out.println(day[j]);
  60. if(day[j]=="Sunday")
  61. {
  62. obj.suspend();
  63. }
  64. else if(day[j]=="Wednesday")
  65. {
  66. obj.resume();
  67. }
  68. }
  69.  
  70. }
  71.  
  72. }
  73. public class Salesman {
  74.  
  75. public static void main(String[] args) {
  76. // TODO Auto-generated method stub
  77. //SynThreads1 q=new SynThreads1();
  78. Day1 d=new Day1();
  79. //new SalesPersons();
  80. //d.start();
  81. }
  82.  
  83. }
Add Comment
Please, Sign In to add comment