20 lines
598 B
Java
20 lines
598 B
Java
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;
|
|
}
|
|
}
|