1/**
2 * Copyright(C) 1998
3 * All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
4 *
5 * Permission to use, copy, modify, and distribute this
6 * software and its documentation for EDUCATIONAL purposes
7 * and without fee is hereby granted provided that this
8 * copyright notice appears in all copies.
9 *
10 * @date : January 1, 1998.
11 * @author : Salih Yurttas.
12 */
13
14
15public class Writer extends Thread {
16
17 private final int RUNS=10;
18
19 private Buffer slot;
20 private int number;
21 private RWMonitor monitor;
22
23 public Writer(RWMonitor monitor,
24 Buffer slot,
25 int number) {
26 this.slot=slot;
27 this.number=number;
28 this.monitor=monitor;
29 }
30
31 public void run() {
32 int value=5;
33
34 for(int i=0; i<RUNS; i++) {
35 monitor.startWrite();
36 slot.put(value);
37 monitor.endWrite();
38
39 System.out.println("Writer #" +
40 this.number +
41 " wrote: " +
42 value);
43 try {
44 Thread.sleep(((long)Math.random())*5);
45 }
46 catch(InterruptedException sleepExcept) {}
47 }
48 }
49
50}