added ex R
This commit is contained in:
19
src/exercises/ex_r/PostOffice.java
Normal file
19
src/exercises/ex_r/PostOffice.java
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user