/* * Teste.java * * Created on 1 de Dezembro de 2001, 13:26 */ package concorrencia; public class Teste { public static Semaforo s; public static void main (String args[]) { s = new Semaforo(1); Runnable r1 = new Runnable(){ public void run(){ while(true){ s.down(); System.out.println("Eu sou a Thread 1"); s.up(); try { Thread.sleep(50); } catch (InterruptedException e) {} } } }; Runnable r2 = new Runnable(){ public void run(){ while(true){ s.down(); System.out.println("Eu sou a Thread 2"); s.up(); try { Thread.sleep(100); } catch (InterruptedException e) {} } } }; Thread t1 = new Thread(r1); Thread t2 = new Thread(r2); t1.start(); t2.start(); } }