@Test public void testObtainExtractor() throws Exception { System.out.println("obtainExtractor"); final CermineExtractorServiceImpl instance = new CermineExtractorServiceImpl(); instance.setThreadPoolSize(3); instance.init(); List<ContentExtractor> list = new ArrayList<ContentExtractor>(); for (int i = 0; i < 3; i++) { list.add(instance.obtainExtractor()); } sleeping = true; new Thread(new Runnable() { @Override public void run() { ContentExtractor res = instance.obtainExtractor(); sleeping = false; } }).start(); assertTrue(sleeping); Thread.sleep(100); assertTrue(sleeping); instance.returnExtractor(list.remove(0)); Thread.sleep(100); assertFalse(sleeping); }
protected ContentExtractor obtainExtractor() { log.debug("Obtaining extractor from the pool"); ContentExtractor res = null; try { synchronized (extractors) { while (extractors.isEmpty()) { log.debug("Extractor pool is empty, going to sleep..."); extractors.wait(); } res = extractors.remove(0); } return res; } catch (InterruptedException ire) { log.error("Unexpected exception while waiting for extractor...", ire); throw new RuntimeException(ire); } }
CermineExtractorServiceImpl implements CermineExtractorService { protected ContentExtractor obtainExtractor() { log.debug("Obtaining extractor from the pool"); ContentExtractor res = null; try { synchronized (extractors) { while (extractors.isEmpty()) { log.debug("Extractor pool is empty, going to sleep..."); extractors.wait(); } res = extractors.remove(0); } return res; } catch (InterruptedException ire) { log.error("Unexpected exception while waiting for extractor...", ire); throw new RuntimeException(ire); } } }
CermineExtractorServiceImpl implements CermineExtractorService { protected ContentExtractor obtainExtractor() { log.debug("Obtaining extractor from the pool"); ContentExtractor res = null; try { synchronized (extractors) { while (extractors.isEmpty()) { log.debug("Extractor pool is empty, going to sleep..."); extractors.wait(); } res = extractors.remove(0); } return res; } catch (InterruptedException ire) { log.error("Unexpected exception while waiting for extractor...", ire); throw new RuntimeException(ire); } } CermineExtractorServiceImpl(); }
CermineExtractorServiceImpl implements CermineExtractorService { protected ContentExtractor obtainExtractor() { log.debug("Obtaining extractor from the pool"); ContentExtractor res = null; try { synchronized (extractors) { while (extractors.isEmpty()) { log.debug("Extractor pool is empty, going to sleep..."); extractors.wait(); } res = extractors.remove(0); } return res; } catch (InterruptedException ire) { log.error("Unexpected exception while waiting for extractor...", ire); throw new RuntimeException(ire); } } CermineExtractorServiceImpl(); @PostConstruct void init(); int getThreadPoolSize(); void setThreadPoolSize(int threadPoolSize); int getMaxQueueForBatch(); void setMaxQueueForBatch(int maxQueueForBatch); @Override ExtractionResult extractNLM(InputStream is); @Override long initExtractionTask(byte[] pdf, String fileName); }
CermineExtractorServiceImpl implements CermineExtractorService { protected ContentExtractor obtainExtractor() { log.debug("Obtaining extractor from the pool"); ContentExtractor res = null; try { synchronized (extractors) { while (extractors.isEmpty()) { log.debug("Extractor pool is empty, going to sleep..."); extractors.wait(); } res = extractors.remove(0); } return res; } catch (InterruptedException ire) { log.error("Unexpected exception while waiting for extractor...", ire); throw new RuntimeException(ire); } } CermineExtractorServiceImpl(); @PostConstruct void init(); int getThreadPoolSize(); void setThreadPoolSize(int threadPoolSize); int getMaxQueueForBatch(); void setMaxQueueForBatch(int maxQueueForBatch); @Override ExtractionResult extractNLM(InputStream is); @Override long initExtractionTask(byte[] pdf, String fileName);  }