-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProducer.java
More file actions
34 lines (31 loc) · 885 Bytes
/
Producer.java
File metadata and controls
34 lines (31 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.util.Random;
/**
* Class that is designed to be run on a thread.
* Each thread adds 50 random numbers to the stack.
*
* @author Kevin Wood
* @version 1.0
*/
public class Producer implements Runnable {
private SynchronizedBoundedStack randomNumbers;
private Random random;
public Producer(SynchronizedBoundedStack randomNumbers) {
this.randomNumbers = randomNumbers;
random = new Random();
}
/**
* Loops through 50 times pushing
* 50 random numbers onto the stack
*/
@Override
public void run() {
for (int i = 0; i < 50; i++) {
try {
int randomNumber = random.nextInt(1000);
randomNumbers.push(randomNumber);
} catch (InterruptedException e) {
System.out.println("Ran Into An Exception");
}
}
}
}