VL-Programmieren/VL14/Aufgabe02/Printer.java

24 lines
551 B
Java
Raw Normal View History

2024-05-30 09:27:24 +00:00
package VL14.Aufgabe02;
/**
* Class which represents a printer.
*
* @author Sebastian Brosch
*/
public class Printer implements Runnable {
public void run() {
while (true) {
synchronized (PrinterQueue.queue) {
if (PrinterQueue.queue.size() > 0) {
2024-06-03 20:04:50 +00:00
System.out.println("Printer " + Thread.currentThread().threadId() + " prints: " + PrinterQueue.queue.poll());
} else {
try {
PrinterQueue.queue.wait();
} catch (InterruptedException e) {
}
2024-05-30 09:27:24 +00:00
}
}
}
}
}