首页 \ 问答 \ Java中的非fork-join执行服务中是否存在等效的isQuiescent?(Is there an equivalent of isQuiescent in non-fork-join executor services in Java?)

Java中的非fork-join执行服务中是否存在等效的isQuiescent?(Is there an equivalent of isQuiescent in non-fork-join executor services in Java?)

我在ForkJoin和FixedSizeThreadPool中实现了我的问题的两个实现,我想比较它们的性能。 在我的问题中,每个任务都会创建一些子任务,并将它们再次提交给执行程序服务。 在fork-join实现中,我使用fork(),而在另一个实现中,我使用execute()。

显然,我的主线程需要等到整个工作完成。 在fork-join中,我可以优雅地检查isQuiescent()属性以确保一切都已完成,但在另一种情况下,我想不出比手动计算我创建了多少任务以及完成了多少任务更好的事情! 这个解决方案有效,但代价是共享变量显然会降低我的性能。

我不能只使用shutdown(),因为那时子任务不会被调度(它们会得到RejectedExecutionException)。

有谁知道比计算任务更好的解决方案?


I have made two implementations of my problem in ForkJoin and FixedSizeThreadPool and I want to compare their performances. In my problem, each task will create some sub-tasks and will submit them to the executor service again. In the fork-join implementation, I use fork() and in the other one, I use execute().

Obviously, my main thread needs to wait until the whole work has finished. In fork-join, I can gracefully check the isQuiescent() property to make sure everything has finished, but in the other case, I cannot think of anything better than manually counting how many tasks I have created and how many have finished! This solution works, but at the cost of a shared variable that obviously reduces my performance.

I cannot just use shutdown(), because then the sub-tasks will not be scheduled (they will get RejectedExecutionException).

Does anybody know a better solution than counting the tasks?


原文:https://stackoverflow.com/questions/14441540
更新时间:2023-07-25 17:07

最满意答案

你的代码看起来很好。

我建议将数组的位置设置为自己的变量,然后尝试使用substr。 然后你可以回显/记录它们并查看它们的设置。


your code looks fine.

i suggest setting that position of your array to its own variable, then try and substr that. then you can echo/log both and see what they are set to.

相关问答

更多
  • 关于substr函数[2022-04-17]

    一、substr函数在oracle中使用表示被截取的字符串或字符串表达式。和instr()函数不同,instr()函数是要截取的字符串在源字符串中的“位置”,substr()函数是截取字符串的“内容”。 二、substr函数返回字符串的一部分。如果 参数start 是负数且 length 小于或等于 start,则 length 为 0。 三、substr是C++语言函数,主要功能是复制子字符串,要求从指定位置开始,并具有指定的长度。 定义和用法: basic_string::substr basic_st ...
  • 由stream_get_meta_data返回的数组中的wrapper_data条目被定义为混合,我不认为你可以假设它将包含什么。 它可能包含NULL条目或其他数组...因为你明确想要查找一个字符串也许: if(is_array($wrapper_data)){ foreach(array_keys($wrapper_data) as $hh){ if (is_string($wrapper_data[$hh]) && substr($wrapper_data[$hh], ...
  • 你的代码看起来很好。 我建议将数组的位置设置为自己的变量,然后尝试使用substr。 然后你可以回显/记录它们并查看它们的设置。 your code looks fine. i suggest setting that position of your array to its own variable, then try and substr that. then you can echo/log both and see what they are set to.
  • " . (strlen($info['post_content'])>200? substr( $info['post_content'],0,200)."...": $info['post_content']). "

    [...]"; 和简单的版本: " . substr( $info['pos ...
  • 您可以将$haystack分解为单个单词,然后对其执行in_array()检查以确保在执行substr_count()之前该单词作为整个单词存在: $animals = array('cat','dog','bird', 'cat', 'dog', 'bird', 'bird', 'hello'); $toString = implode(' ', $animals); $data = array('cat'); function substr_count_array($haystack, $needle ...
  • 使用SUBSTR() 。 SELECT name FROM students WHERE SUBSTR(name , -1) = 'a' Using SUBSTR(). SELECT name FROM students WHERE SUBSTR(name , -1) = 'a'
  • tapes[i][j]是字符',' ,并且该字符没有substr方法。 您可能想要在字符串对象tapes[i]上调用substr ,而不是在单个字符上。 另外:在位置j找到逗号后,您可以调用substr( i -counter, counter) 。 这是你的意图吗? tapes[i][j] is the character ',', and that character has no substr method. You probably wanted to call substr on the stri ...
  • CBroe让我找到了问题的答案。 字符串以空格为前缀,直到我们有16个字符。 所以substr工作正常,我回到了2个空间,没有出现在回声中。 var_dump($ var)让我深入了解了这一点。 CBroe gave the to finding the answer to my problem. The string was prefixed with spaces till there we're 16 characters. So the substr was working correctly, i ...
  • 如果你必须专门检查前8个字符,那么你应该在执行子字符串之前从字符串中删除
    : if (substr(str_replace("
    ", "", $str), 0, 8) == "{source}") 如果字符串稍有不同,即
    ,则无效。 最好的方法可能是: if (strpos($str, "{source}") !== false) 编辑 这个怎么样? 它应该在{source}{/source}标记之间获取文本并将它们拆分; ,然后将第一个条目作为函数名称,将第二个条目作为函数的 ...
  • 是和否,因为substr返回一个字符串 ,在你的情况下是针,在失败时返回FALSE ,在这种情况下它不是in_array函数的有效参数。 您应该首先使用substr提取字符串的一部分,并且需要确保提取了一些字符串并且它没有返回FALSE ,然后才应该在in_array使用它。 Yes & NO because substr returns a string which is needle in your case and FALSE on failure in which case it won't be ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。