All pastes #908633 Raw Edit

Something

public java v1 · immutable
·published 2008-02-18 17:12 UTC
rendered paste body
public class Worker implements Runnable {		private int id; //thread id	private Book b; //the instance of book created in main	public Worker(int i, Book book) {		id = i;		b = book;	}		public void run() {				double random = 0; //random value to determine read or write		while (!Thread.interrupted()) { 							random = Math.random(); //random orly?							//if > 0.5 then read, otherwise write				String action = random > 0.5 ? "is requesting read lock." : "is requesting write lock.";									System.out.println("Thread " + id + " " + action);								if (random > 0.5 ) b.getReadLock(this.id);										else b.getWriteLock(id);		}					b.releaseReadLock(id);		b.releaseWriteLock(id);							System.out.println("Thread " + id + " interrupted....exiting");		System.exit(0);	}}