public FileWatcher(final RegisterWatchService monitor) { this.monitor = monitor; this.pool = new DefaultThreadPool("watcher", 1); }
public DefaultThreadPool(final String prefix, final int size, final Priority priority, final Thread.UncaughtExceptionHandler handler) { super(createExecutor(prefix, size, priority, handler)); }
final DefaultThreadPool executor = new DefaultThreadPool(String.format("http-%s", url), 1); final Future<CloseableHttpResponse> future = executor.execute(new Callable<CloseableHttpResponse>() { @Override public CloseableHttpResponse call() throws Exception {
@Override public Response getResponse() throws IOException { final CloseableHttpResponse response; try { response = future.get(); } catch(InterruptedException e) { throw new IOException(e); } catch(ExecutionException e) { throw new IOException(e.getCause()); } finally { executor.shutdown(false); } return new CommonsHttpResponse(response); }
final DefaultThreadPool executor = new DefaultThreadPool(String.format("http-%s", url), 1); final Future<CloseableHttpResponse> future = executor.execute(new Callable<CloseableHttpResponse>() { @Override public CloseableHttpResponse call() throws Exception {
@Override public Response finish() throws IOException { final CloseableHttpResponse response; try { response = future.get(); } catch(InterruptedException e) { throw new IOException(e); } catch(ExecutionException e) { throw new IOException(e.getCause()); } finally { executor.shutdown(false); } final Map<String, List<String>> responseHeaders = new HashMap<String, List<String>>(); for(org.apache.http.Header header : response.getAllHeaders()) { // Ignore multiple headers with the same name responseHeaders.put(header.getName(), Collections.singletonList(header.getValue())); } return new Response(response.getStatusLine().getStatusCode(), new HttpMethodReleaseInputStream(response), responseHeaders); } };
public DispatchThreadPool(final String prefix, final int size, final Priority priority, final Thread.UncaughtExceptionHandler handler) { super(PreferencesFactory.get().getInteger("threading.pool.size.max") == size ? new DispatchExecutorService() : DefaultThreadPool.createExecutor(prefix, size, priority, handler)); } }