/** * Class readerwriter: defines a main method that starts 4 readers and * 4 writers and waits until these 8 threads have terminated. * @author Kg2s */ public class readerwriter { // initialize objects and variables /**Starts 4 readers and writers which share the scheduler class */ public static void main(String args[]){ scheduler s = new scheduler(); timer t = new timer(); int numThreads=4; writerx[] w = new writerx[numThreads]; readerx[] r = new readerx[numThreads]; //Initialize writers for(int i=0;i<numThreads;i++) w[i]= new writerx(i,t,s); //Initialize readers for(int i=0;i<numThreads;i++) r[i]= new readerx(i,t,s); System.out.println("Starting the threads....\n"); //start writers for(int i=0;i<numThreads;i++) w[i].start(); //start readers for(int i=0;i<numThreads;i++) r[i].start(); } }