Por Lucas Fernandes da Costa 2016.1 package trab1; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; public class Main { public static void main(String[] args) throws InterruptedException { ScheduledExecutorService ste = Executors.newScheduledThreadPool(1); ExecutorService te = Executors.newFixedThreadPool(4); Buffer buffer = new Buffer(); for (int i = 1; i <= 120; i++) { ste.scheduleAtFixedRate(new Escritor(buffer), 0, 1, TimeUnit.MILLISECONDS); te.execute(new Leitor(buffer)); } } } ======================================================= package trab1; public class Escritor implements Runnable { private Buffer buffer; private static int valor = 0; public Escritor(Buffer buffer){ this.buffer = buffer; } @Override public void run() { buffer.escrever(valor++); } } ======================================================== package trab1; public class Leitor implements Runnable { public Buffer buffer; public Leitor(Buffer buffer){ this.buffer = buffer; } @Override public void run() { buffer.ler(); } } ========================================================= package trab1; public class Buffer { int valor; boolean ocupado = false; public synchronized void escrever(int valor) { while (ocupado) { try { wait(); } catch (InterruptedException ex) { ex.printStackTrace(); } } ocupado = true; this.valor = valor; System.out.println("Escreveu " + valor); notifyAll(); } public synchronized int ler() { while (!ocupado) { try { wait(); } catch (InterruptedException ex) { ex.printStackTrace(); } } ocupado = false; System.out.println("Leu: " + this.valor); notify(); return valor; } } ===========================================================