Advertisement
chojuaib

Untitled new

Jan 31st, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. package ejercicios;
  2.  
  3. import static es.urjc.etsii.code.concurrency.SimpleConcurrent.*;
  4.  
  5. public class ejercicio2{
  6.  
  7. static volatile int x;
  8. static volatile boolean done;
  9.  
  10. public static void productor(){
  11.  
  12. do {
  13.  
  14. while(done);
  15. x = (int)(Math.random()*100);
  16. done = true;
  17.  
  18. }while(true);
  19.  
  20. }
  21.  
  22. public static void consumidor() {
  23.  
  24. do {
  25. while(!done);
  26. println("He generado el numero:");
  27. println("x = " + x);
  28. done = false;
  29.  
  30. }while(true);
  31.  
  32. }
  33.  
  34. public static void main(String[] args) {
  35.  
  36. createThread("productor");
  37. createThread("consumidor");
  38. startThreadsAndWait();
  39.  
  40. }
  41.  
  42. }
  43. RAW Paste Data
  44. package ejercicios;
  45.  
  46. import static es.urjc.etsii.code.concurrency.SimpleConcurrent.*;
  47.  
  48. public class ejercicio2{
  49.  
  50. static volatile int x;
  51. static volatile boolean done;
  52.  
  53. public static void productor(){
  54.  
  55. do {
  56.  
  57. while(done);
  58. x = (int)(Math.random()*100);
  59. done = true;
  60.  
  61. }while(true);
  62.  
  63. }
  64.  
  65. public static void consumidor() {
  66.  
  67. do {
  68. while(!done);
  69. println("He generado el numero:");
  70. println("x = " + x);
  71. done = false;
  72.  
  73. }while(true);
  74.  
  75. }
  76.  
  77. public static void main(String[] args) {
  78.  
  79. createThread("productor");
  80. createThread("consumidor");
  81. startThreadsAndWait();
  82.  
  83. }
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement