-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support TTL Wrapper for Functional Interface like Supplier | 对Supplier方式提交的任务支持不友好 #162
Comments
考虑上面2个原因,就像
|
使用java8中的CompletableFuture类对外接口并没有Callable类型的输入,取而代之的是Suppiler,Suppiler转换Callable很丑陋 TtlCallable<Object> objectTtlCallable = TtlCallable.get(supplier::get);
CompletableFuture.supplyAsync(() -> {
try {
return objectTtlCallable.call();
} catch (Exception e) {
throw new RuntimeException(e);
}
}, executor); |
1. 对
|
发布了 <dependency>
<groupId>com.alibaba</groupId>
<artifactId>transmittable-thread-local</artifactId>
<version>2.11.4</version>
</dependency> @liuzhongkai 试试,看看是不是OK的? import com.alibaba.ttl.TtlWrappers;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;
public class SupplierTtlWrapperDemo {
public static void main(String[] args) throws Exception {
final Supplier<String> supplier = () -> "42";
final CompletableFuture<String> future = CompletableFuture.supplyAsync(
TtlWrappers.wrap(supplier));
System.out.println(future.get());
}
} 更多详见JavaDoc |
support TTL Wrapper for Functional Interface like Supplier.
Otherwise need convert
Supplier
toCallable
, this is not convenient.需要将
Supplier
转换为Callable
The text was updated successfully, but these errors were encountered: