package com.example.domain;

public class Producer implements Runnable {

	private SyncStack theStack;
	private int num;
	private static int counter = 1;

	public Producer(SyncStack s) {
		theStack = s;
		num = counter++;
	}

	@Override
	public void run() {
		char c;
		for (int i = 0; i < 10; i++) {
			// generate a random character
			c = (char) (Math.random() * 26 + 'A');
			theStack.push(c);
			System.out.println("Producer" + num + ": " + c);
		}
		// put thread to sleep
		try {
			Thread.sleep((int) (Math.random() * 1000));
		} catch (InterruptedException ex) {
			// ignore
		}
	}
}
