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
最满意答案
你的代码看起来很好。
我建议将数组的位置设置为自己的变量,然后尝试使用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 ... -
警告:substr()期望参数1是字符串,数组在[重复](Warning: substr() expects parameter 1 to be string, array given in [duplicate])[2023-01-21]
由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替换LIKE(Replace LIKE by SUBSTR)[2023-10-26]
使用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 ...
-
substr没有返回值(substr not returning a value)[2021-12-03]
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 ...