public void run() { for (int i = 0; i < 10; i++) { cubbyhole.put(i); System.out.println("exercise.Producer #" + this.number + " put: " + i); try { sleep((int) (Math.random() * 100)); } catch (InterruptedException e) { } } }
public void run() { try { for (int i = 0; i < 10; i++) { cubbyhole.put(i); sleep((int) (Math.random() * 100)); } } catch (InterruptedException e) { } finally { System.out.println("Goodbye from Producer (" + Thread.currentThread().getName() + ")"); } }