在本文中,我们将详细介绍NoSuchMethodError:com.google.common.util.concurrent.MoreExecutors.directExecutor在弹性搜索jar
在本文中,我们将详细介绍NoSuchMethodError:com.google.common.util.concurrent.MoreExecutors.directExecutor在弹性搜索jar中发生冲突的各个方面,同时,我们也将为您带来关于api-java.util.concurrent.ThreadPoolExecutor、com.facebook.common.executors.CallerThreadExecutor的实例源码、com.facebook.common.executors.UiThreadImmediateExecutorService的实例源码、com.google.common.util.concurrent.AbstractExecutionThreadService的实例源码的有用知识。
本文目录一览:- NoSuchMethodError:com.google.common.util.concurrent.MoreExecutors.directExecutor在弹性搜索jar中发生冲突
- api-java.util.concurrent.ThreadPoolExecutor
- com.facebook.common.executors.CallerThreadExecutor的实例源码
- com.facebook.common.executors.UiThreadImmediateExecutorService的实例源码
- com.google.common.util.concurrent.AbstractExecutionThreadService的实例源码
NoSuchMethodError:com.google.common.util.concurrent.MoreExecutors.directExecutor在弹性搜索jar中发生冲突
创建Elasticsearch
Client时,出现异常java.lang.NoSuchMethodError:com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava
/ util / concurrent / Executor;
经过一些查找之后,像Guava-18这样的接缝在运行时会被旧版本覆盖,而Guava-18仅在编译任务期间起作用。
我的Maven配置如下:
<build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.0</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.4.1</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/> </transformers> </configuration> </execution> </executions> </plugin> </plugins></build>
如何在执行时强制使用Guava-18版本?
答案1
小编典典您应该尝试查找番石榴的“旧”版本的来源,并将其全部排除一次。
查找依赖项:
mvn dependency:tree | grep guava
排除它:
<dependency> <groupId>org.whatever</groupId> <artifactId>the_lib_that_includes_guava</artifactId> <version>0.97</version> <exclusions> <exclusion> <artifactId>com.google</artifactId> <groupId>guava</groupId> </exclusion> </exclusions></dependency>
有关依赖关系排除的更多信息,请参见https://maven.apache.org/guides/introduction/introduction-
to-optional-and-excludes-
dependencies.html。
api-java.util.concurrent.ThreadPoolExecutor
I、UML
II、依赖
III、运行流程
IV、生命周期
run state | desc |
---|---|
RUNNING | 能接收新任务,且能处理队列中任务 |
SHUTDOWN | 不能接收新任务,但能继续处理队列中任务 |
STOP | 新任务和队列中任务都不能处理,会中断正在处理任务的线程 |
TIDYING | 所有任务已终止 |
TERMINATED | terminated()之后的状态 |
V、任务调度
1、首先检测线程池运行状态,如果不是RUNNING,则直接拒绝,线程池要保证在RUNNING的状态下执行任务。
2、如果workerCount < corePoolSize,则创建并启动一个线程来执行新提交的任务。
3、如果workerCount >= corePoolSize,且线程池内的阻塞队列未满,则将任务添加到该阻塞队列中。
4、如果workerCount >= corePoolSize && workerCount < maximumPoolSize,且线程池内的阻塞队列已满,则创建并启动一个线程来执行新提交的任务。
5、如果workerCount >= maximumPoolSize,并且线程池内的阻塞队列已满, 则根据拒绝策略来处理该任务, 默认的处理方式是直接抛异常。
VI、Worker
1、任务是 Runnable(内部变量名叫 task 或 command),线程是 Worker。
2、Worker持有一个线程thread
3、Worker是通过继承AQS,使用AQS来实现独占锁这个功能。没有使用可重入锁ReentrantLock,而是使用AQS,为的就是实现不可重入的特性去反应线程现在的执行状态。
——lock方法一旦获取了独占锁,表示当前线程正在执行任务中。
——如果正在执行任务,则不应该中断线程。
——如果该线程现在不是独占锁的状态,也就是空闲的状态,说明它没有在处理任务,这时可以对该线程进行中断。
——线程池在执行shutdown方法或tryTerminate方法时会调用interruptIdleWorkers方法来中断空闲的线程,interruptIdleWorkers方法会使用tryLock方法来判断线程池中的线程是否是空闲状态;如果线程是空闲状态则可以安全回收。
4、执行任务流程
VII、需要关注和验证的几个重要知识点
1、线程池初始化线程数是可动态调整的。调小时任务将重新进入for循环。验证调大和调小时任务是否有影响。
2、线程池一方面避免了处理任务时创建销毁线程开销的代价,另一方面避免了线程数量膨胀导致的过分调度问题,保证了对内核的充分利用。创建销毁线程的开销、调度线程的开销。怎么验证这两种开销???
3、设置的线程数过多可能还会引发线程上下文切换频繁的问题,也会降低处理任务的速度,降低吞吐量???还是怎么验证开销???
4、最大核心数设置偏小,大量抛出RejectedExecutionException,触发接口降级条件。就是说是一种动态降级的方案。
5、队列设置过长,最大线程数设置失效,导致请求数量增加时,大量任务堆积在队列中,任务执行时间过长。嵌套的线程池,会不会出现第一层的任务正在执行,与之关联的第二层任务正在等待,从而导致响应时间长???
VIII、参考文章:
https://www.javadoop.com/post/java-thread-pool
https://tech.meituan.com/2020/04/02/java-pooling-pratice-in-meituan.html
com.facebook.common.executors.CallerThreadExecutor的实例源码
public IncreasingQualityDataSource() { mFinishedDataSources = new AtomicInteger(0); final int n = mDataSourcesuppliers.size(); mNumberOfDataSources = n; mIndexOfDataSourceWithResult = n; mDataSources = new ArrayList<>(n); for (int i = 0; i < n; i++) { DataSource<T> dataSource = mDataSourcesuppliers.get(i).get(); mDataSources.add(dataSource); dataSource.subscribe(new InternalDataSubscriber(i),CallerThreadExecutor.getInstance()); // there's no point in creating data sources of lower quality // if the data source of a higher quality has some result already if (dataSource.hasResult()) { break; } } }
public void setUp() { mSrc1 = mock(DataSource.class); mSrc2 = mock(DataSource.class); mSrc3 = mock(DataSource.class); mDataSourcesupplier1 = mock(supplier.class); mDataSourcesupplier2 = mock(supplier.class); mDataSourcesupplier3 = mock(supplier.class); when(mDataSourcesupplier1.get()).thenReturn(mSrc1); when(mDataSourcesupplier2.get()).thenReturn(mSrc2); when(mDataSourcesupplier3.get()).thenReturn(mSrc3); mDataSubscriber = mock(DataSubscriber.class); mExecutor = CallerThreadExecutor.getInstance(); mInorder = inorder( mSrc1,mSrc2,mSrc3,mDataSourcesupplier1,mDataSourcesupplier2,mDataSourcesupplier3,mDataSubscriber); msuppliers = Arrays.asList( mDataSourcesupplier1,mDataSourcesupplier3); }
@Before public void setUp() { mDeferredReleaser = mock(DeferredReleaser.class); mCallerContext = mock(Object.class); mDataSourcesupplier = mock(supplier.class); mDraweeHierarchy = mock(SettableDraweeHierarchy.class); mUiThreadExecutor = CallerThreadExecutor.getInstance(); mController = new FakeDraweeController( mDeferredReleaser,mUiThreadExecutor,mDataSourcesupplier,"id",mCallerContext); doAnswer( new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { ((DeferredReleaser.Releasable) invocation.getArguments()[0]).release(); return null; } }).when(mDeferredReleaser).scheduleDeferredRelease(any(DeferredReleaser.Releasable.class)); when(mDataSourcesupplier.get()).thenReturn(SimpleDataSource.<FakeImage>create()); }
public static void loadBitmapFromUrl(Context context,String url,String cookie,String referer,BaseBitmapDataSubscriber dataSubscriber) { if (TextUtils.isEmpty(url)) return; Uri uri = Uri.parse(url); JsonObject header = new JsonObject(); header.addProperty("Cookie",cookie); header.addProperty("Referer",referer); if (HProxy.isEnabled() && HProxy.isAllowPicture()) { HProxy proxy = new HProxy(url); header.addProperty(proxy.getHeaderKey(),proxy.getHeaderValue()); } MyOkHttpNetworkFetcher.headers.put(uri,getGson().toJson(header)); ImagePipeline imagePipeline = Fresco.getimagePipeline(); ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(uri); ImageRequest request = builder.build(); DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(request,context); dataSource.subscribe(dataSubscriber,CallerThreadExecutor.getInstance()); }
public static void loadResourceFromUrl(Context context,Uri uri,BaseDataSubscriber dataSubscriber) { if (uri.getScheme().startsWith("http")) { JsonObject header = new JsonObject(); header.addProperty("Cookie",cookie); header.addProperty("Referer",referer); if (HProxy.isEnabled() && HProxy.isAllowPicture()) { HProxy proxy = new HProxy(uri.toString()); header.addProperty(proxy.getHeaderKey(),proxy.getHeaderValue()); } MyOkHttpNetworkFetcher.headers.put(uri,getGson().toJson(header)); } ImagePipeline imagePipeline = Fresco.getimagePipeline(); ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(uri); ImageRequest request = builder.build(); DataSource<CloseableReference<PooledByteBuffer>> dataSource = imagePipeline.fetchEncodedImage(request,CallerThreadExecutor.getInstance()); }
public void setsupplier(@Nullable supplier<DataSource<T>> supplier) { // early return without calling {@code supplier.get()} in case we are closed if (isClosed()) { return; } DataSource<T> oldDataSource; DataSource<T> newDataSource = (supplier != null) ? supplier.get() : null; synchronized (RetainingDataSource.this) { if (isClosed()) { oldDataSource = newDataSource; newDataSource = null; } else { oldDataSource = mDataSource; mDataSource = newDataSource; } } if (newDataSource != null) { newDataSource.subscribe(new InternalDataSubscriber(),CallerThreadExecutor.getInstance()); } closeSafely(oldDataSource); }
public static void LoadImageFromURLAndCallBack(SimpleDraweeView destimageView,String URL,Context context,BaseBitmapDataSubscriber bbds) { int w = destimageView.getWidth(); int h =destimageView.getHeight(); if(w<1){ w = destimageView.getLayoutParams().width; } if(h<1){ h =destimageView.getLayoutParams().height; } ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(URL)) .setResizeOptions(new ResizeOptions(w,h)) .setProgressiveRenderingEnabled(true) .build(); ImagePipeline imagePipeline = Fresco.getimagePipeline(); DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest,context); dataSource.subscribe(bbds,CallerThreadExecutor.getInstance()); DraweeController draweeController = Fresco.newDraweeControllerBuilder() .setimageRequest(imageRequest) .setoldController(destimageView.getController()) .setAutoplayAnimations(true) .build(); destimageView.setController(draweeController); }
public static void LoadImageFromURIAndCallBack(SimpleDraweeView destimageView,BaseBitmapDataSubscriber bbds) { int w = destimageView.getWidth(); int h =destimageView.getHeight(); if(w<1){ w = destimageView.getLayoutParams().width; } if(h<1){ h =destimageView.getLayoutParams().height; } ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(uri) .setResizeOptions(new ResizeOptions(w,CallerThreadExecutor.getInstance()); DraweeController draweeController = Fresco.newDraweeControllerBuilder() .setimageRequest(imageRequest) .setoldController(destimageView.getController()) .setAutoplayAnimations(true) .build(); destimageView.setController(draweeController); }
public void setsupplier(@Nullable supplier<DataSource<T>> supplier) { // early return without calling {@code supplier.get()} in case we are closed if (isClosed()) { return; } DataSource<T> oldDataSource; DataSource<T> newDataSource = (supplier != null) ? supplier.get() : null; synchronized (RetainingDataSource.this) { if (isClosed()) { closeSafely(newDataSource); return; } else { oldDataSource = mDataSource; mDataSource = newDataSource; } } if (newDataSource != null) { newDataSource.subscribe(new InternalDataSubscriber(),CallerThreadExecutor.getInstance()); } closeSafely(oldDataSource); }
public IncreasingQualityDataSource() { mFinishedDataSources = new AtomicInteger(0); final int n = mDataSourcesuppliers.size(); mNumberOfDataSources = n; mIndexOfDataSourceWithResult = n; mDataSources = new ArrayList<>(n); for (int i = 0; i < n; i++) { DataSource<T> dataSource = mDataSourcesuppliers.get(i).get(); mDataSources.add(dataSource); dataSource.subscribe(new InternalDataSubscriber(i),CallerThreadExecutor.getInstance()); // there's no point in creating data sources of lower quality // if the data source of a higher quality has some result already if (dataSource.hasResult()) { break; } } }
public void setUp() { mSrc1 = mock(DataSource.class); mSrc2 = mock(DataSource.class); mSrc3 = mock(DataSource.class); mDataSourcesupplier1 = mock(supplier.class); mDataSourcesupplier2 = mock(supplier.class); mDataSourcesupplier3 = mock(supplier.class); when(mDataSourcesupplier1.get()).thenReturn(mSrc1); when(mDataSourcesupplier2.get()).thenReturn(mSrc2); when(mDataSourcesupplier3.get()).thenReturn(mSrc3); mDataSubscriber = mock(DataSubscriber.class); mExecutor = CallerThreadExecutor.getInstance(); mInorder = inorder( mSrc1,mDataSourcesupplier3); }
@Before public void setUp() { mDeferredReleaser = mock(DeferredReleaser.class); mCallerContext = mock(Object.class); mDataSourcesupplier = mock(supplier.class); mDraweeHierarchy = mock(SettableDraweeHierarchy.class); mUiThreadExecutor = CallerThreadExecutor.getInstance(); mController = new FakeDraweeController( mDeferredReleaser,mCallerContext); doAnswer( new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { ((DeferredReleaser.Releasable) invocation.getArguments()[0]).release(); return null; } }).when(mDeferredReleaser).scheduleDeferredRelease(any(DeferredReleaser.Releasable.class)); when(mDataSourcesupplier.get()).thenReturn(SimpleDataSource.<FakeImage>create()); }
private boolean startNextDataSource() { supplier<DataSource<T>> dataSourcesupplier = getNextsupplier(); DataSource<T> dataSource = (dataSourcesupplier != null) ? dataSourcesupplier.get() : null; if (setCurrentDataSource(dataSource) && dataSource != null) { dataSource.subscribe(new InternalDataSubscriber(),CallerThreadExecutor.getInstance()); return true; } else { closeSafely(dataSource); return false; } }
public static <T> ListDataSource<T> create( DataSource<CloseableReference<T>>... dataSources) { Preconditions.checkNotNull(dataSources); Preconditions.checkState(dataSources.length > 0); ListDataSource<T> listDataSource = new ListDataSource<T>(dataSources); for (DataSource<CloseableReference<T>> dataSource : dataSources) { if (dataSource != null) { dataSource.subscribe( listDataSource.new InternalDataSubscriber(),CallerThreadExecutor.getInstance()); } } return listDataSource; }
@Before public void setUp() { MockitoAnnotations.initMocks(this); mResult1 = new Object(); mResult2 = new Object(); mResult3 = new Object(); mException = mock(Exception.class); mDataSubscriber1 = mock(DataSubscriber.class); mDataSubscriber2 = mock(DataSubscriber.class); mSettableProducerContext = mock(SettableProducerContext.class); when(mSettableProducerContext.getId()).thenReturn(mRequestId); when(mSettableProducerContext.isPrefetch()).thenReturn(true); mProducer = mock(Producer.class); mDataSource = ProducerToDataSourceAdapter.create( mProducer,mSettableProducerContext,mRequestListener); ArgumentCaptor<Consumer> captor = ArgumentCaptor.forClass(Consumer.class); verify(mRequestListener).onRequestStart( mSettableProducerContext.getimageRequest(),mSettableProducerContext.getCallerContext(),mRequestId,mSettableProducerContext.isPrefetch()); verify(mProducer).produceResults(captor.capture(),any(SettableProducerContext.class)); mInternalConsumer = captor.getValue(); mDataSource.subscribe(mDataSubscriber1,CallerThreadExecutor.getInstance()); }
private void testSubscribe(int expected) { mDataSource.subscribe(mDataSubscriber2,CallerThreadExecutor.getInstance()); switch (expected) { case NO_INteraCTIONS: break; case ON_NEW_RESULT: verify(mDataSubscriber2).onNewResult(mDataSource); break; case ON_FAILURE: verify(mDataSubscriber2).onFailure(mDataSource); break; } verifyNoMoreInteractionsAndReset(); }
@Before public void setUp() { MockitoAnnotations.initMocks(this); mResourceReleaser = mock(ResourceReleaser.class); mResultRef1 = CloseableReference.of(new Object(),mResourceReleaser); mResultRef2 = CloseableReference.of(new Object(),mResourceReleaser); mResultRef3 = CloseableReference.of(new Object(),mResourceReleaser); mException = mock(Exception.class); mDataSubscriber1 = mock(DataSubscriber.class); mDataSubscriber2 = mock(DataSubscriber.class); mSettableProducerContext = mock(SettableProducerContext.class); when(mSettableProducerContext.getId()).thenReturn(mRequestId); when(mSettableProducerContext.isPrefetch()).thenReturn(false); mProducer = mock(Producer.class); mDataSource = CloseableProducerToDataSourceAdapter.create( mProducer,CallerThreadExecutor.getInstance()); }
private void testSubscribe(int expected) { mDataSource.subscribe(mDataSubscriber2,CallerThreadExecutor.getInstance()); switch (expected) { case NO_INteraCTIONS: break; case ON_NEW_RESULT: verify(mDataSubscriber2).onNewResult(mDataSource); break; case ON_FAILURE: verify(mDataSubscriber2).onFailure(mDataSource); break; } verifyNoMoreInteractionsAndReset(); }
@Before public void setUp() { MockitoAnnotations.initMocks(this); mSettableDataSource1 = SettableDataSource.create(); mSettableDataSource2 = SettableDataSource.create(); mListDataSource = ListDataSource.create(mSettableDataSource1,mSettableDataSource2); mRef1 = CloseableReference.of(1,mResourceReleaser); mRef2 = CloseableReference.of(2,mResourceReleaser); mRuntimeException = new RuntimeException(); mListDataSource.subscribe(mDataSubscriber,CallerThreadExecutor.getInstance()); }
@Before public void setUp() { MockitoAnnotations.initMocks(this); mThrottlingProducer = new ThrottlingProducer<Object>( MAX_SIMULTANEOUS_REQUESTS,CallerThreadExecutor.getInstance(),mInputProducer); for (int i = 0; i < 5; i++) { mConsumers[i] = mock(Consumer.class); mProducerContexts[i] = mock(ProducerContext.class); mProducerListeners[i] = mock(ProducerListener.class); mRequestIds[i] = Integer.toString(i); mResults[i] = mock(Object.class); when(mProducerContexts[i].getListener()).thenReturn(mProducerListeners[i]); when(mProducerContexts[i].getId()).thenReturn(mRequestIds[i]); final int iFinal = i; doAnswer( new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { mThrottlerConsumers[iFinal] = (Consumer<Object>) invocation.getArguments()[0]; return null; } }).when(mInputProducer).produceResults(any(Consumer.class),eq(mProducerContexts[i])); } }
public static void getBitmapWithFresco(Context context,BaseBitmapDataSubscriber baseBitmapDataSubscriber) { ImageRequest imageRequest = ImageRequestBuilder .newBuilderWithSource(Uri.parse(url)) .setProgressiveRenderingEnabled(true) .build(); ImagePipeline imagePipeline = Fresco.getimagePipeline(); DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest,context); dataSource.subscribe(baseBitmapDataSubscriber,CallerThreadExecutor.getInstance()); }
public static void LoadImageFromURLAndCallBack(SimpleDraweeView destimageView,BaseBitmapDataSubscriber bbds,BasePostprocessor postprocessor) { int w = destimageView.getWidth(); int h =destimageView.getHeight(); if(w<1){ w = destimageView.getLayoutParams().width; } if(h<1){ h =destimageView.getLayoutParams().height; } ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(URL)) .setResizeOptions(new ResizeOptions(w,h)) .setProgressiveRenderingEnabled(true); if(postprocessor!=null){ builder.setPostprocessor(postprocessor); } ImageRequest imageRequest = builder .build(); ImagePipeline imagePipeline = Fresco.getimagePipeline(); DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest,CallerThreadExecutor.getInstance()); DraweeController draweeController = Fresco.newDraweeControllerBuilder() .setimageRequest(imageRequest) .setoldController(destimageView.getController()) .setAutoplayAnimations(true) .build(); destimageView.setController(draweeController); }
private boolean startNextDataSource() { supplier<DataSource<T>> dataSourcesupplier = getNextsupplier(); DataSource<T> dataSource = (dataSourcesupplier != null) ? dataSourcesupplier.get() : null; if (setCurrentDataSource(dataSource) && dataSource != null) { dataSource.subscribe(new InternalDataSubscriber(),CallerThreadExecutor.getInstance()); return true; } else { closeSafely(dataSource); return false; } }
public static <T> ListDataSource<T> create( DataSource<CloseableReference<T>>... dataSources) { Preconditions.checkNotNull(dataSources); Preconditions.checkState(dataSources.length > 0); ListDataSource<T> listDataSource = new ListDataSource<T>(dataSources); for (DataSource<CloseableReference<T>> dataSource : dataSources) { if (dataSource != null) { dataSource.subscribe( listDataSource.new InternalDataSubscriber(),CallerThreadExecutor.getInstance()); } } return listDataSource; }
@Before public void setUp() { MockitoAnnotations.initMocks(this); mResult1 = new Object(); mResult2 = new Object(); mResult3 = new Object(); mException = mock(Exception.class); mDataSubscriber1 = mock(DataSubscriber.class); mDataSubscriber2 = mock(DataSubscriber.class); mSettableProducerContext = mock(SettableProducerContext.class); when(mSettableProducerContext.getId()).thenReturn(mRequestId); when(mSettableProducerContext.isPrefetch()).thenReturn(true); mProducer = mock(Producer.class); mDataSource = ProducerToDataSourceAdapter.create( mProducer,CallerThreadExecutor.getInstance()); }
private void testSubscribe(int expected) { mDataSource.subscribe(mDataSubscriber2,CallerThreadExecutor.getInstance()); switch (expected) { case NO_INteraCTIONS: break; case ON_NEW_RESULT: verify(mDataSubscriber2).onNewResult(mDataSource); break; case ON_FAILURE: verify(mDataSubscriber2).onFailure(mDataSource); break; } verifyNoMoreInteractionsAndReset(); }
@Before public void setUp() { MockitoAnnotations.initMocks(this); mResourceReleaser = mock(ResourceReleaser.class); mResultRef1 = CloseableReference.of(new Object(),CallerThreadExecutor.getInstance()); }
private void testSubscribe(int expected) { mDataSource.subscribe(mDataSubscriber2,CallerThreadExecutor.getInstance()); switch (expected) { case NO_INteraCTIONS: break; case ON_NEW_RESULT: verify(mDataSubscriber2).onNewResult(mDataSource); break; case ON_FAILURE: verify(mDataSubscriber2).onFailure(mDataSource); break; } verifyNoMoreInteractionsAndReset(); }
@Before public void setUp() { MockitoAnnotations.initMocks(this); mSettableDataSource1 = SettableDataSource.create(); mSettableDataSource2 = SettableDataSource.create(); mListDataSource = ListDataSource.create(mSettableDataSource1,CallerThreadExecutor.getInstance()); }
@Before public void setUp() { MockitoAnnotations.initMocks(this); mThrottlingProducer = new ThrottlingProducer<Object>( MAX_SIMULTANEOUS_REQUESTS,eq(mProducerContexts[i])); } }
public DataFetchProducer( PooledByteBufferFactory pooledByteBufferFactory) { super(CallerThreadExecutor.getInstance(),pooledByteBufferFactory); }
private static final void setSubscribe(Context context,ImageRequest request,BaseDataSubscriber subscriber) { ImagePipeline imagePipeline = Fresco.getimagePipeline(); DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(request,context); dataSource.subscribe(subscriber,CallerThreadExecutor.getInstance()); }
public DataFetchProducer( PooledByteBufferFactory pooledByteBufferFactory) { super(CallerThreadExecutor.getInstance(),pooledByteBufferFactory); }
com.facebook.common.executors.UiThreadImmediateExecutorService的实例源码
void attach(BitmapUpdateListener listener) { mBitmapUpdateListener = listener; mAttachCounter++; if (mAttachCounter != 1) { // this is a secondary attach,ignore it,only updating Bitmap boundaries if needed. Bitmap bitmap = getBitmap(); if (bitmap != null) { listener.onSecondaryAttach(bitmap); } return; } listener.onImageLoadEvent(ImageLoadEvent.ON_LOAD_START); Assertions.assertCondition(mDataSource == null); Assertions.assertCondition(mImageRef == null); // Submit the request ImagePipeline imagePipeline = ImagePipelineFactory.getInstance().getimagePipeline(); mDataSource = imagePipeline.fetchDecodedImage(mImageRequest,RCtimageView.getCallerContext()); mDataSource.subscribe(this,UiThreadImmediateExecutorService.getInstance()); }
public PipelineDraweeControllerBuildersupplier( Context context,ImagePipelineFactory imagePipelineFactory,Set<ControllerListener> boundControllerListeners,@Nullable DraweeConfig draweeConfig) { mContext = context; mImagePipeline = imagePipelineFactory.getimagePipeline(); if (draweeConfig != null && draweeConfig.getPipelineDraweeControllerFactory() != null) { mPipelineDraweeControllerFactory = draweeConfig.getPipelineDraweeControllerFactory(); } else { mPipelineDraweeControllerFactory = new PipelineDraweeControllerFactory(); } mPipelineDraweeControllerFactory.init( context.getResources(),DeferredReleaser.getInstance(),imagePipelineFactory.getAnimatedDrawableFactory(context),UiThreadImmediateExecutorService.getInstance(),mImagePipeline.getBitmapMemoryCache(),draweeConfig != null ? draweeConfig.getCustomDrawableFactories() : null,draweeConfig != null ? draweeConfig.getDebugOverlayEnabledsupplier() : null); mBoundControllerListeners = boundControllerListeners; }
public VolleyDraweeControllerBuildersupplier( Context context,ImageLoader imageLoader,Set<ControllerListener> boundControllerListeners) { mContext = context; mImageLoader = imageLoader; mVolleyDraweeControllerFactory = new VolleyDraweeControllerFactory( context.getResources(),UiThreadImmediateExecutorService.getInstance()); mBoundControllerListeners = boundControllerListeners; }
private ExperimentalBitmapAnimationDrawableFactory createDrawableFactory() { supplier<Integer> cachingStrategysupplier = new supplier<Integer>() { @Override public Integer get() { return ExperimentalBitmapAnimationDrawableFactory.CACHING_STRATEGY_FRESCO_CACHE_NO_REUSING; } }; final SerialExecutorService serialExecutorServiceForFramePreparing = new DefaultSerialExecutorService(mExecutorsupplier.forDecode()); supplier<Integer> numberOfFramesToPreparesupplier = new supplier<Integer>() { @Override public Integer get() { return NUMBER_OF_FRAMES_TO_PREPARE; } }; return new ExperimentalBitmapAnimationDrawableFactory( getAnimatedDrawableBackendProvider(),serialExecutorServiceForFramePreparing,RealtimeSinceBootClock.get(),mPlatformBitmapFactory,mbackingCache,cachingStrategysupplier,numberOfFramesToPreparesupplier); }
/** * Wraps the given animation backend with an activity check. * When no frame has been drawn for more than 2 seconds,an inactivity toast message will * be displayed. * * @param context the context to be used for displaying the toast message * @param animationBackend the backend to wrap with the inactivity check * @return the wrapped backend to use */ public static AnimationBackend wrapAnimationBackendWithInactivityCheck( final Context context,final AnimationBackend animationBackend) { AnimationBackendDelegateWithInactivityCheck.InactivityListener inactivityListener = new AnimationBackendDelegateWithInactivityCheck.InactivityListener() { @Override public void onInactive() { // Forward the inactive callback to the backend if needed if (animationBackend instanceof AnimationBackendDelegateWithInactivityCheck.InactivityListener) { ((AnimationBackendDelegateWithInactivityCheck.InactivityListener) animationBackend) .onInactive(); } Toast.makeText( context,"Animation backend inactive.",Toast.LENGTH_SHORT) .show(); } }; return createForBackend( animationBackend,inactivityListener,UiThreadImmediateExecutorService.getInstance()); }
public PipelineDraweeControllerBuildersupplier( Context context,draweeConfig != null ? draweeConfig.getDebugOverlayEnabledsupplier() : null); mBoundControllerListeners = boundControllerListeners; }
public VolleyDraweeControllerBuildersupplier( Context context,UiThreadImmediateExecutorService.getInstance()); mBoundControllerListeners = boundControllerListeners; }
private ExperimentalBitmapAnimationDrawableFactory createDrawableFactory() { supplier<Integer> cachingStrategysupplier = new supplier<Integer>() { @Override public Integer get() { return ExperimentalBitmapAnimationDrawableFactory.CACHING_STRATEGY_FRESCO_CACHE_NO_REUSING; } }; final SerialExecutorService serialExecutorServiceForFramePreparing = new DefaultSerialExecutorService(mExecutorsupplier.forDecode()); supplier<Integer> numberOfFramesToPreparesupplier = new supplier<Integer>() { @Override public Integer get() { return NUMBER_OF_FRAMES_TO_PREPARE; } }; return new ExperimentalBitmapAnimationDrawableFactory( getAnimatedDrawableBackendProvider(),numberOfFramesToPreparesupplier); }
/** * Wraps the given animation backend with an activity check. * When no frame has been drawn for more than 2 seconds,UiThreadImmediateExecutorService.getInstance()); }
public void get() { ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(imageUrl)) .build(); ImagePipeline imagePipeline = Fresco.getimagePipeline(); DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(request,WikipediaApp.getInstance()); dataSource.subscribe(new BitmapDataSubscriber(),UiThreadImmediateExecutorService.getInstance()); }
com.google.common.util.concurrent.AbstractExecutionThreadService的实例源码
public AdbShellProcess(final AndroidDevice device,final AndroidProcessBuilder builder) { this.device = device; this.builder = builder; this.workingDir = device.getTempDir() + "/" + UUID.randomUUID(); this.device.deleteOnClose(this.workingDir); this.stdErr = builder.redirectErrorStream() ? AdbShellStream.getNull() : AdbShellStream.get(builder.redirectError(),System.err); /* Our exit code future */ this.exitFuture = SettableFuture.create(); /* Set up a service that just maps to our own functions */ this.service = new AbstractExecutionThreadService() { @Override protected void startUp() throws IOException { AdbShellProcess.this.startUp(); } @Override protected void run() throws IOException,InterruptedException { AdbShellProcess.this.run(); } @Override protected void shutDown() { AdbShellProcess.this.shutDown(); } }; service.addListener(new Service.Listener() { @Override public void Failed(final Service.State from,final Throwable failure) { AdbShellProcess.this.onFail(failure); } },MoreExecutors.sameThreadExecutor()); service.startAsync(); }
关于NoSuchMethodError:com.google.common.util.concurrent.MoreExecutors.directExecutor在弹性搜索jar中发生冲突的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于api-java.util.concurrent.ThreadPoolExecutor、com.facebook.common.executors.CallerThreadExecutor的实例源码、com.facebook.common.executors.UiThreadImmediateExecutorService的实例源码、com.google.common.util.concurrent.AbstractExecutionThreadService的实例源码等相关内容,可以在本站寻找。
本文标签: