package loimed; import java.io.*; public class Kirjutaja2 implements Runnable { PipedReader allikas; int viivitus; Object lukk; public Kirjutaja2(PipedReader allikas, int viivitus, Object lukk) { this.allikas = allikas; this.viivitus = viivitus; this.lukk = lukk; } public void run() { BufferedReader br = new BufferedReader(allikas); try { String rida = br.readLine(); while (rida != null) { System.out.println("Ootab luku avanemist "+Thread.currentThread()); synchronized (lukk) { System.out.println("Saabus: " + rida+" "+Thread.currentThread()); Thread.sleep(viivitus); System.out.println("Vabanes: "+Thread.currentThread()+"\n"); } rida = br.readLine(); } } catch (Exception ex) { ex.printStackTrace(); } System.out.println("Kirjutaja ots"); } }