假設這是一個「單例」實現:我保證這隻會調用一次productCatalogLoader.load(),並且不會出現任何空指針?任何方法來使這更簡單? private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
private ProductCatalog productCatalog;
public Pr
我有一個類從BlockingQueue採取對象,並通過連續循環呼叫take()來處理它們。在某些時候,我知道沒有更多的對象會被添加到隊列中。我如何中斷take()方法以阻止阻塞? 下面是處理的對象的類: public class MyObjHandler implements Runnable {
private final BlockingQueue<MyObj> queue;