/* Producers-Consumers */ /* Multithreads implementation */ /* File Producers_Consumers.java */ /* Main program */ public class prova2 { public static void main(String[] args) { Process1 p1 = new Process1(); p1.start(); new Process2(p1).start(); } } class Process2 extends Thread { private Process1 p; public Process2(Process1 p1) { p = p1; } public void run() { try { sleep(1000); p.interrupt(); } catch (InterruptedException e) { return; } } } class Process1 extends Thread { // public Process1(){} public void sl() throws InterruptedException { System.out.println("going to sleep"); sleep(100); System.out.println("waken up"); } public void run() { try { while (!isInterrupted()){ sl(); } } catch (InterruptedException e) { System.out.println("interrupted"); Thread.currentThread().interrupt(); } } }