首页 \ 问答 \ 等待所有任务完成(Waiting for all the tasks to finish)

等待所有任务完成(Waiting for all the tasks to finish)

我使用相同的线程池完成了一系列不同的“任务”。 我想测量执行每项任务所需的时间,但为此我需要等待“任务”中的每项任务(抱歉模棱两可)才能完成。

当我只做一个任务时,我通常会这样做:

ExecutorService e = Executors.newCachedThreadPool();
for (int i=0; i<100; ++i)
    e.submit(target);
e.shutdown();
while (!e.isTerminated());

但由于将有几个任务提交到池中,我不能失望。 与等待任务完成提及“关闭请求后”有关的所有方法。 那么,如果我不想关闭它,但是等待所有线程完成然后提交更多任务呢?

这就是我想要做的:

ExecutorService e = Executors.newCachedThreadPool();
for (int i=0; i<100; ++i)
    e.submit(target);
// wait for all targets to finish
for (int i=0; i<100; ++i)
    e.submit(target); // submit different tasks
// wait... and so on

我想过关闭池然后再使用prestartAllCoreThreads “唤醒它”,但后来我意识到这不是ExecutorService方法而是ThreadPoolExecutor方法。 这可能是一个解决方案吗? 关闭它,等待,然后再次激活池? 对我来说似乎有点难看。

我还认为最自然的事情是使用CyclicBarrier ,但这似乎是一种特定的方式,而我认为能够使用任何ExecutorService进行我正在尝试的事情是最合乎逻辑的事情。去做。

有什么方法可以坚持ExecutorService并等待所有任务完成?


I have a series of different "tasks" to be done using the same thread pool. I want to measure the time it takes to perform each task, but for that I need to wait for every task in the "task" (sorry for ambiguity) to finish.

When there's just one task I would normally do this:

ExecutorService e = Executors.newCachedThreadPool();
for (int i=0; i<100; ++i)
    e.submit(target);
e.shutdown();
while (!e.isTerminated());

But since there will be several task submitted to the pool, I can't it down. All the methods that have something to do with waiting for the tasks to finish mention "after shutdown request". Well, what if I don't want to shut it down, but wait for all the threads to finish and then submit more tasks?

This is what I want to do:

ExecutorService e = Executors.newCachedThreadPool();
for (int i=0; i<100; ++i)
    e.submit(target);
// wait for all targets to finish
for (int i=0; i<100; ++i)
    e.submit(target); // submit different tasks
// wait... and so on

I thought of shutting the pool down and then "waking it up" again using prestartAllCoreThreads, but then I realized this was not an ExecutorService method but a ThreadPoolExecutor method. Could this be a solution? Shutting it down, waiting, and then activating the pool again? Seems a bit ugly to me.

I also thought that the most natural thing to do was to use a CyclicBarrier, but it seems too a specific way of doing this, while I think it would be the most logical thing to be able to use any ExecutorService for what I'm trying to do.

Is there any way I could stick to ExecutorServices and wait for all the tasks to finish?


原文:https://stackoverflow.com/questions/24362798
更新时间:2023-08-30 07:08

最满意答案

默认情况下,此设置设置为“关”。 无论如何,您可以编辑此文件。 它位于:

/installdir/php/etc/php.ini

稍后,您应该重新启动服务以使更改生效。 您可以通过执行此命令来执行此操作。

/installdir/ctlscript.sh重启


By default, this setting is set to Off. Anyway, you can edit this file. It is located at:

/installdir/php/etc/php.ini

Later, you should restart the services for changes to take effect. You can do it by executing this command.

/installdir/ctlscript.sh restart

相关问答

更多
  • 你试过这个吗? ini_set('max_input_vars', 2500); 在这个文件的开头bootstrap/autoload.php Have you tried this? ini_set('max_input_vars', 2500); At the beginning of this file bootstrap/autoload.php
  • 我已经解决了我的问题。 在第109行的php.ini中有一个语法错误,所以下一个所有语法都不会排除 I have solved my question. there is a syntax error in php.ini in line 109,so the next all syntax not excute
  • 根据上面@PeeHaa提供的方向,我们决定将我们的应用程序锁定到特定的PHP版本(通过Composer ),获取Apache版本和CLI的PHP版本的默认php.ini文件,并添加到我们的设置中。 然后将其推送到我们的repo,并在部署和文件的任何git更改时根据需要进行复制。 仅供参考,在我们的Debian环境中,我们遵循此处概述的策略,安装除最新版本之外的特定版本的PHP。 Per the direction provided by @PeeHaa above, we've decided to loc ...
  • 最后一个变量值规则 [PHP] ; My changed configuration lines before original php.ini settings expose_php = Off expose_php = On 所以它 变量会按照从左到右的顺序依次被覆盖,最右边的每次都会赢得手牌。 last variable value rules [PHP] ; My changed configuration lines before original php.ini settings expose ...
  • 好吧希望这可以防止其他人将头撞到墙上好几个小时。 我已经找到了我自己的解决方案干净建立我的PHP。 事实证明,你可以改变with-config-file-path选项并让它改变phpinfo()和php -ini输出中显示的路径。 但是,如果你不清理你的构建,那么设置实际使用的地方就不会被重建,并且会破坏你的构建。 自我注意:始终清理您的构建。 我之前知道这一点,但事实上重建确实改变了php告诉我目录的事实。 Ok hopefully this will prevent someone else from ...
  • 使用-c选项,您可以指定应使用哪个php.ini文件: php -c /etc/php.ini your-php-script.php 作为参考,请参阅php --help的输出php --help : $ php --help Usage: php [options] [-f] [--] [args...] php [options] -r [--] [args...] php [options] [-B ] -R
  • 默认情况下,此设置设置为“关”。 无论如何,您可以编辑此文件。 它位于: /installdir/php/etc/php.ini 稍后,您应该重新启动服务以使更改生效。 您可以通过执行此命令来执行此操作。 /installdir/ctlscript.sh重启 By default, this setting is set to Off. Anyway, you can edit this file. It is located at: /installdir/php/etc/php.ini Later, y ...
  • 将其添加到.htaccess文件中 php_value upload_max_filesize 24M php_value post_max_size 32M php_value memory_limit 32M 您的PHP设置将每次上载的最大文件大小限制为有限的MB。 根据您的服务器环境,可能会在系统范围的php.ini文件中更改这些设置。 Add this to your .htaccess file php_value upload_max_filesize 24M php_value post_m ...
  • 这不是100%的工作解决方案,但尝试执行以下步骤: 将通用php.ini文件复制到/var/www/my-website.com文件夹: cp /etc/php.ini /var/www/my-website.com/ 根据需要编辑自定义的php.ini文件并保存 找到apache配置文件httpd.conf并找到与您的本地域my-website.com相关的VirtualHost部分 将PHPINIDir指令添加到上一节: DocumentRoot /var/ww ...
  • 您无法在运行时更改short_open_tag设置(这是phpunit.xml的配置正在执行的操作)。 如果查看文档 ,则short_open_tag位于PHP_INI_PERDIR组中。 这意味着它只能在php.ini , .htaccess , httpd.conf或.user.ini 。 You cannot change the short_open_tag setting at runtime (which is what the configuration in phpunit.xml is d ...

相关文章

更多

最新问答

更多
  • 获取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的基本操作命令。。。