public synchronized ExecutorService executorService() { if (executorService == null) { executorService = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, TimeUnit.SECONDS, new SynchronousQueue<>(), Util.threadFactory("OkHttp Dispatcher", false)); } return executorService; }
/** * Create a cache which will reside in {@code directory}. This cache is lazily initialized on * first access and will be created if it does not exist. * * @param directory a writable directory * @param valueCount the number of values per cache entry. Must be positive. * @param maxSize the maximum number of bytes this cache should use to store */ public static DiskLruCache create(FileSystem fileSystem, File directory, int appVersion, int valueCount, long maxSize) { if (maxSize <= 0) { throw new IllegalArgumentException("maxSize <= 0"); } if (valueCount <= 0) { throw new IllegalArgumentException("valueCount <= 0"); } // Use a single background thread to evict entries. Executor executor = new ThreadPoolExecutor(0, 1, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), Util.threadFactory("OkHttp DiskLruCache", true)); return new DiskLruCache(fileSystem, directory, appVersion, valueCount, maxSize, executor); }
public synchronized ExecutorService executorService() { if (executorService == null) { executorService = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, TimeUnit.SECONDS, new SynchronousQueue<>(), Util.threadFactory("OkHttp Dispatcher", false)); } return executorService; }
/** * 返回一个全局公用的线程池,适用于大多数异步需求。 * 避免多个线程池创建带来的资源消耗。 * * @return {@link Executor} */ @Singleton @Provides ExecutorService provideExecutorService() { return mExecutorService == null ? new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), Util.threadFactory("Arms Executor", false)) : mExecutorService; }
started = true; executor = Executors.newCachedThreadPool(Util.threadFactory("MockWebServer", false)); this.inetSocketAddress = inetSocketAddress; serverSocket = serverSocketFactory.createServerSocket();
public void initReaderAndWriter(String name, Streams streams) throws IOException { synchronized (this) { this.streams = streams; this.writer = new WebSocketWriter(streams.client, streams.sink, random); this.executor = new ScheduledThreadPoolExecutor(1, Util.threadFactory(name, false)); if (pingIntervalMillis != 0) { executor.scheduleAtFixedRate( new PingRunnable(), pingIntervalMillis, pingIntervalMillis, MILLISECONDS); } if (!messageAndCloseQueue.isEmpty()) { runWriter(); // Send messages that were enqueued before we were connected. } } reader = new WebSocketReader(streams.client, streams.source, this); }
/** * Create a cache which will reside in {@code directory}. This cache is lazily initialized on * first access and will be created if it does not exist. * * @param directory a writable directory * @param valueCount the number of values per cache entry. Must be positive. * @param maxSize the maximum number of bytes this cache should use to store */ public static DiskLruCache create(FileSystem fileSystem, File directory, int appVersion, int valueCount, long maxSize) { if (maxSize <= 0) { throw new IllegalArgumentException("maxSize <= 0"); } if (valueCount <= 0) { throw new IllegalArgumentException("valueCount <= 0"); } // Use a single background thread to evict entries. Executor executor = new ThreadPoolExecutor(0, 1, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), Util.threadFactory("OkHttp DiskLruCache", true)); return new DiskLruCache(fileSystem, directory, appVersion, valueCount, maxSize, executor); }
Util.threadFactory(Util.format("OkHttp %s Writer", connectionName), false)); if (builder.pingIntervalMillis != 0) { writerExecutor.scheduleAtFixedRate(new PingRunnable(false, 0, 0), Util.threadFactory(Util.format("OkHttp %s Push Observer", connectionName), true)); peerSettings.set(Settings.INITIAL_WINDOW_SIZE, DEFAULT_INITIAL_WINDOW_SIZE); peerSettings.set(Settings.MAX_FRAME_SIZE, Http2.INITIAL_MAX_FRAME_SIZE);
public void initReaderAndWriter(String name, Streams streams) throws IOException { synchronized (this) { this.streams = streams; this.writer = new WebSocketWriter(streams.client, streams.sink, random); this.executor = new ScheduledThreadPoolExecutor(1, Util.threadFactory(name, false)); if (pingIntervalMillis != 0) { executor.scheduleAtFixedRate( new PingRunnable(), pingIntervalMillis, pingIntervalMillis, MILLISECONDS); } if (!messageAndCloseQueue.isEmpty()) { runWriter(); // Send messages that were enqueued before we were connected. } } reader = new WebSocketReader(streams.client, streams.source, this); }
Util.threadFactory(Util.format("OkHttp %s Writer", connectionName), false)); if (builder.pingIntervalMillis != 0) { writerExecutor.scheduleAtFixedRate(new PingRunnable(false, 0, 0), Util.threadFactory(Util.format("OkHttp %s Push Observer", connectionName), true)); peerSettings.set(Settings.INITIAL_WINDOW_SIZE, DEFAULT_INITIAL_WINDOW_SIZE); peerSettings.set(Settings.MAX_FRAME_SIZE, Http2.INITIAL_MAX_FRAME_SIZE);
public synchronized ExecutorService executorService() { if (executorService == null) { executorService = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), Util.threadFactory("OkHttp Dispatcher", false)); } return executorService; }
public synchronized ExecutorService getExecutorService() { if (executorService == null) { executorService = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), Util.threadFactory("OkHttp Dispatcher", false)); } return executorService; }
public synchronized ExecutorService executorService() { if (executorService == null) { executorService = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), Util.threadFactory("OkHttp Dispatcher", false)); } return executorService; }
public synchronized ExecutorService getExecutorService() { if (executorService == null) { executorService = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), Util.threadFactory("OkHttp Dispatcher", false)); } return executorService; }
public synchronized ExecutorService executorService() { if (executorService == null) { executorService = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), Util.threadFactory("OkHttp Dispatcher", false)); } return executorService; }
/** * 返回一个全局公用的线程池,适用于大多数异步需求。 * 避免多个线程池创建带来的资源消耗。 * * @return {@link Executor} */ @Singleton @Provides ExecutorService provideExecutorService() { return mExecutorService == null ? new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), Util.threadFactory("Art Executor", false)) : mExecutorService; }
static RealWebSocket create(StreamAllocation streamAllocation, Response response, Random random, WebSocketListener listener) { String url = response.request().url().toString(); ThreadPoolExecutor replyExecutor = new ThreadPoolExecutor(1, 1, 1, SECONDS, new LinkedBlockingDeque<Runnable>(), Util.threadFactory(Util.format("OkHttp %s WebSocket", url), true)); replyExecutor.allowCoreThreadTimeOut(true); return new StreamWebSocket(streamAllocation, random, replyExecutor, listener, url); }
static Dispatcher newDispatcher(int maxRequests) { // bound the executor so that we get consistent performance ThreadPoolExecutor dispatchExecutor = new ThreadPoolExecutor(0, maxRequests, 60, TimeUnit.SECONDS, // Using a synchronous queue means messages will send immediately until we hit max // in-flight requests. Once max requests are hit, send will block the caller, which is // the AsyncReporter flush thread. This is ok, as the AsyncReporter has a buffer of // unsent spans for this purpose. new SynchronousQueue<>(), Util.threadFactory("OkHttpSender Dispatcher", false)); Dispatcher dispatcher = new Dispatcher(dispatchExecutor); dispatcher.setMaxRequests(maxRequests); dispatcher.setMaxRequestsPerHost(maxRequests); return dispatcher; }
public void initReaderAndWriter(String name, Streams streams) throws IOException { synchronized (this) { this.streams = streams; this.writer = new WebSocketWriter(streams.client, streams.sink, random); this.executor = new ScheduledThreadPoolExecutor(1, Util.threadFactory(name, false)); if (pingIntervalMillis != 0) { executor.scheduleAtFixedRate( new PingRunnable(), pingIntervalMillis, pingIntervalMillis, MILLISECONDS); } if (!messageAndCloseQueue.isEmpty()) { runWriter(); // Send messages that were enqueued before we were connected. } } reader = new WebSocketReader(streams.client, streams.source, this); }
public void initReaderAndWriter( String name, long pingIntervalMillis, Streams streams) throws IOException { synchronized (this) { this.streams = streams; this.writer = new WebSocketWriter(streams.client, streams.sink, random); this.executor = new ScheduledThreadPoolExecutor(1, Util.threadFactory(name, false)); if (pingIntervalMillis != 0) { executor.scheduleAtFixedRate( new PingRunnable(), pingIntervalMillis, pingIntervalMillis, MILLISECONDS); } if (!messageAndCloseQueue.isEmpty()) { runWriter(); // Send messages that were enqueued before we were connected. } } reader = new WebSocketReader(streams.client, streams.source, this); }