Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ejercicios;
- import static es.urjc.etsii.code.concurrency.SimpleConcurrent.*;
- public class ejercicio2{
- static volatile int x;
- static volatile boolean done;
- public static void productor(){
- do {
- while(done);
- x = (int)(Math.random()*100);
- done = true;
- }while(true);
- }
- public static void consumidor() {
- do {
- while(!done);
- println("He generado el numero:");
- println("x = " + x);
- done = false;
- }while(true);
- }
- public static void main(String[] args) {
- createThread("productor");
- createThread("consumidor");
- startThreadsAndWait();
- }
- }
- RAW Paste Data
- package ejercicios;
- import static es.urjc.etsii.code.concurrency.SimpleConcurrent.*;
- public class ejercicio2{
- static volatile int x;
- static volatile boolean done;
- public static void productor(){
- do {
- while(done);
- x = (int)(Math.random()*100);
- done = true;
- }while(true);
- }
- public static void consumidor() {
- do {
- while(!done);
- println("He generado el numero:");
- println("x = " + x);
- done = false;
- }while(true);
- }
- public static void main(String[] args) {
- createThread("productor");
- createThread("consumidor");
- startThreadsAndWait();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement