added ex R

This commit is contained in:
2025-01-06 15:18:17 +01:00
parent 53add330f4
commit a7216b1642
5 changed files with 94 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
package exercises.ex_r;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
public class PostOffice {
private BlockingQueue<Package> packages = new LinkedBlockingQueue<>();
public void registerPackage(Package pkg) {
packages.add(pkg);
System.out.println("Registered " + pkg + " (now " + packages.size() + ")");
}
public Package takePackage() throws InterruptedException {
Package pkg = packages.take();
System.out.println("Withdrawn " + pkg + " (now " + packages.size() + ")");
return pkg;
}
}