在运行并发测试(了解并发性)时,假定要计算搜索结果的类在python调用期间未返回。
仅当我按如下所述设置测试,并且其他测试(一个请求没有执行器服务等)完成而没有任何问题时,才会发生此行为。
在以下设置下,什么会导致此问题?
@Test
public void concurrent() {
CountDownLatch latch = new CountDownLatch(1);
AtomicBoolean running = new AtomicBoolean();
AtomicInteger overlaps = new AtomicInteger();
int threads = 1;
ExecutorService service =
Executors.newFixedThreadPool(threads);
Collection<Future<Integer>> futures =
new ArrayList<>(threads);
for (int t = 0; t < threads; ++t) {
futures.add(
service.submit(
() -> {
// latch.await();
if (running.get()) {
overlaps.incrementAndGet();
}
running.set(true);
FAEnvironmentSizeDescriptor sizeDesc = compute(payload);
running.set(false);
return null;
}
)
);
}
}
该类中的python标注非常标准:
pbExec = new ProcessExec(pb, output, stdin, true);
还尝试了Process
,由于某种原因,它在运行测试时没有返回。