我需要在我正在处理的异步框架中提交任务,但我需要捕获异常,并在"中止"之前多次重试相同的任务.
我正在使用的代码是:
int retries = 0;
public CompletableFuture<Result> executeActionAsync() {
// Execute the action async and get the future
CompletableFuture<Result> f = executeMycustomActionHere();
// If the future completes with exception:
f.exceptionally(ex -> {
retries++; // Increment the retry count
if (retries < MAX_RETRIES)
return executeActionAsync(); // <--- Submit one more time
// Abort with a null value
return null;
});
// Return the future
return f;
}
Run Code Online (Sandbox Code Playgroud)
这当前不能编译,因为lambda的返回类型是错误的:它期望a Result
,但executeActionAsync
返回a CompletableFuture<Result>
.
如何实现这个完全异步重试逻辑?
我发现这个职位,说明如何进行转一个8x8矩阵的字节24点的操作,和几个卷轴后有代码实现转置.但是,这种方法没有利用我们可以阻止 8x8转置为4个4x4转置的事实,并且每个转换只能在一个shuffle指令中完成(这篇文章是参考文献).所以我推出了这个解决方案:
__m128i transpose4x4mask = _mm_set_epi8(15, 11, 7, 3, 14, 10, 6, 2, 13, 9, 5, 1, 12, 8, 4, 0);
__m128i shuffle8x8Mask = _mm_setr_epi8(0, 1, 2, 3, 8, 9, 10, 11, 4, 5, 6, 7, 12, 13, 14, 15);
void TransposeBlock8x8(uint8_t *src, uint8_t *dst, int srcStride, int dstStride) {
__m128i load0 = _mm_set_epi64x(*(uint64_t*)(src + 1 * srcStride), *(uint64_t*)(src + 0 * srcStride));
__m128i load1 = _mm_set_epi64x(*(uint64_t*)(src + 3 * srcStride), *(uint64_t*)(src + …
Run Code Online (Sandbox Code Playgroud) 是否可以从内部在链中注入a ?CompletableFuture
CompletableFuture
我正在使用这样的函数:
public CompletableFuture<Boolean> getFutureOfMyLongRunningTask() {
CompletableFuture<Boolean> future = CompletableFuture.supplyAsync(() -> {
// ... Some processing here ...
if (somecondition failed)
return false; // Task failed!
return true; // OK
}).thenApplyAsync((Boolean result) -> {
if (!result) // check of previous stage fail
return false;
// ... Some processing here ...
if (!some condition satisfied) {
// This is where I want the injection to happen.
// This stage should be suspended and a …
Run Code Online (Sandbox Code Playgroud) asynchronous ×2
c ×2
concurrency ×2
java ×2
java-8 ×2
exception ×1
fftw ×1
future ×1
matrix ×1
optimization ×1
simd ×1
sse ×1