Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Ejercicios;
- import static es.urjc.etsii.code.concurrency.SimpleConcurrent.createThread;
- import static es.urjc.etsii.code.concurrency.SimpleConcurrent.sleepRandom;
- import static es.urjc.etsii.code.concurrency.SimpleConcurrent.startThreadsAndWait;
- public class Cliente_servidor {
- public static volatile int numero;
- public static volatile boolean peticionHecha, peticionCompletada;
- public static void cliente() {
- while(true) {
- numero = (int)(Math.random()*9);
- peticionCompletada = false;
- peticionHecha = true;
- while(!peticionCompletada);
- System.out.println("Dato: " + numero);
- }
- }
- public static void servidor() {
- while(true) {
- while(!peticionHecha);
- numero += 7;
- peticionHecha=false;
- peticionCompletada=true;
- }
- }
- public static void main(String[] args) {
- peticionHecha = peticionCompletada = false;
- createThread("cliente");
- createThread("servidor");
- startThreadsAndWait();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement