简体   繁体   English

如何在Java ExecutorService中调试返回期货的Callable

[英]How to debug a Callable in Java ExecutorService that returns Futures

I have an ExecutorService that I use to multithread the processing of the some text, and the unit of work to be applied to a given chunk of text is defined as my ParserCallable which returns a Payload. 我有一个ExecutorService,用于对某些文本进行多线程处理,并将要应用于给定文本块的工作单元定义为返回有效载荷的ParserCallable。

So I have a List> list; 所以我有一个列表>列表;

which is populated by handing off chunks of work to each ParserCallable. 通过将大量工作交给每个ParserCallable来填充。

I want to debug ParserCallable in this multithreaded environment, and I don't have any concern for which one, but I'm not sure how I can step into the execution of any ParserCallable's from my code. 我想在这种多线程环境中调试ParserCallable,并且我不关心哪一个,但是我不确定如何从我的代码中执行任何ParserCallable的执行。

Which looks something like 看起来像

List<Future<PayLoad>> list = new ArrayList<Future<PayLoad>>();
ExecutorService executor = Executors.newFixedThreadPool(25);
for (int i = 0; i < blocks_of_work.size(); i++) {
   Callable<PayLoad> worker = new ParserCallable(blocks_of_work.get(i));
   Future<PayLoad> submit = executor.submit(worker);
   list.add(submit);
}

How I can debug any given ParserCallable in order to troubleshoot some errors I'm getting? 我如何调试任何给定的ParserCallable以便解决一些错误? Based on my code I'm not sure how to step into one of these callables. 根据我的代码,我不确定如何进入这些可调用对象之一。

You need to put a break point in the callable itself. 您需要在可调用对象本身中放置一个断点。

From a computer science theoretic standpoint, it's possible to enable smooth debugging (after all why does your language care whether the operation was sync or async?) but I don't believe this is supported in any mainstream language, like Java, yet. 从计算机科学理论的角度来看,可以进行顺畅的调试(毕竟为什么您的语言关心操作是同步还是异步?),但是我不相信任何主流语言(例如Java)都支持此功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM