W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
我們提供LazyTraceExecutor
,TraceableExecutorService
和TraceableScheduledExecutorService
。每次提交,調(diào)用或計劃新任務(wù)時,這些實現(xiàn)都會創(chuàng)建spans。
以下示例顯示了使用CompletableFuture
時如何將跟蹤信息傳遞給TraceableExecutorService
:
CompletableFuture<Long> completableFuture = CompletableFuture.supplyAsync(() -> { // perform some logic return 1_000_000L; }, new TraceableExecutorService(beanFactory, executorService, // 'calculateTax' explicitly names the span - this param is optional "calculateTax"));
Sleuth不適用于
parallelStream()
。如果要使跟蹤信息通過流傳播,則必須使用supplyAsync(…?)
的方法,如前所示。
如果有beans實現(xiàn)了您想從跨度創(chuàng)建中排除的Executor
接口,則可以使用spring.sleuth.async.ignored-beans
屬性,在其中可以提供bean名稱的列表。
有時,您需要設(shè)置AsyncExecutor
的自定義實例。以下示例顯示如何設(shè)置這樣的自定義Executor
:
@Configuration @EnableAutoConfiguration @EnableAsync // add the infrastructure role to ensure that the bean gets auto-proxied @Role(BeanDefinition.ROLE_INFRASTRUCTURE) static class CustomExecutorConfig extends AsyncConfigurerSupport { @Autowired BeanFactory beanFactory; @Override public Executor getAsyncExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); // CUSTOMIZE HERE executor.setCorePoolSize(7); executor.setMaxPoolSize(42); executor.setQueueCapacity(11); executor.setThreadNamePrefix("MyExecutor-"); // DON'T FORGET TO INITIALIZE executor.initialize(); return new LazyTraceExecutor(this.beanFactory, executor); } }
為確保對配置進(jìn)行后期處理,請記住在
@Configuration
類上添加@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: