W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
我們提供LazyTraceExecutor
,TraceableExecutorService
和TraceableScheduledExecutorService
。每次提交,調(diào)用或計(jì)劃新任務(wù)時(shí),這些實(shí)現(xiàn)都會(huì)創(chuàng)建spans。
以下示例顯示了使用CompletableFuture
時(shí)如何將跟蹤信息傳遞給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實(shí)現(xiàn)了您想從跨度創(chuàng)建中排除的Executor
接口,則可以使用spring.sleuth.async.ignored-beans
屬性,在其中可以提供bean名稱的列表。
有時(shí),您需要設(shè)置AsyncExecutor
的自定義實(shí)例。以下示例顯示如何設(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); } }
為確保對(duì)配置進(jìn)行后期處理,請(qǐng)記住在
@Configuration
類上添加@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: