在.NET下,
谢谢。
System.Action
提供以下方法:
Invoke()
BeginInvoke(AsyncCallback, object)
EndInvoke(IAsyncresult)
谢谢。
从Java 7
开始,您可以使用Executors
框架。您可以找到一些示例:这里
其中一个示例(从上面的链接复制而来 - 示例是针对Java 8
的,因为使用了lambda
):
Callable<Integer> task = () -> {
try {
TimeUnit.SECONDS.sleep(1);
return 123;
}
catch (InterruptedException e) {
throw new IllegalStateException("task interrupted", e);
}
};
ExecutorService executor = Executors.newFixedThreadPool(1);
Future<Integer> future = executor.submit(task);
调用等效:
int result = task.call();
BeginInvoke的等效方法:
Future<Integer> future = executor.submit(task);
EndInvoke的等价物:
int result = future.get();
System.Action
等价的东西。 - Cheng Chen