我如何知道Fork和Join在Java中的池大小是否足够?(How do I know if Fork and Join has enough pool size in Java?)
我正试图对一些大数据实施分而治之的解决方案。 我使用fork和join来把事情分解成线程。 不过,我有一个关于fork机制的问题:如果我将分而治之条件设置为:
@Override protected SomeClass compute(){ if (list.size()<LIMIT){ //Do something here ... }else{ //Divide the list and invoke sub-threads SomeRecursiveTaskClass subWorker1 = new SomeRecursiveTaskClass(list.subList()); SomeRecursiveTaskClass subWorker2 = new SomeRecursiveTaskClass(list.subList()); invokeAll(subWorker1, subWorker2); ... } }
如果没有足够的资源调用
subWorker
会发生什么(例如池中没有足够的线程)? Fork / Join框架是否为可用线程维护池大小? 还是应该将这个条件加入我的分而治之逻辑?I am trying to implement a divide-and-conquer solution to some large data. I use fork and join to break down things into threads. However I have a question regarding the fork mechanism: if I set my divide and conquer condition as:
@Override protected SomeClass compute(){ if (list.size()<LIMIT){ //Do something here ... }else{ //Divide the list and invoke sub-threads SomeRecursiveTaskClass subWorker1 = new SomeRecursiveTaskClass(list.subList()); SomeRecursiveTaskClass subWorker2 = new SomeRecursiveTaskClass(list.subList()); invokeAll(subWorker1, subWorker2); ... } }
What will happen if there is not enough resource to invoke
subWorker
(e.g. not enough thread in pool)? Does Fork/Join framework maintains a pool size for available threads? Or should I add this condition into my divide-and-conquer logic?
原文:https://stackoverflow.com/questions/48157596
最满意答案
...根据我们的经验,应用程序不使用doc:app生成API ...如果团队绝对需要为内部目的生成应用程序文档,他们仍然可以轻松编写自己的任务...
通过在/lib/tasks/documentation.rake中创建一个文件,可以轻松恢复该功能,其中包含以下内容,取自官方任务的最新版本 :
# /lib/tasks/documentation.rake require 'rdoc/task' namespace :doc do RDoc::Task.new("app") { |rdoc| rdoc.rdoc_dir = 'doc/app' rdoc.template = ENV['template'] if ENV['template'] rdoc.title = ENV['title'] || 'Rails Application Documentation' rdoc.options << '--line-numbers' rdoc.options << '--charset' << 'utf-8' rdoc.rdoc_files.include('README.md') rdoc.rdoc_files.include('app/**/*.rb') rdoc.rdoc_files.include('lib/**/*.rb') } Rake::Task['doc:app'].comment = "Generate docs for the app -- also available doc:rails, doc:guides (options: TEMPLATE=/rdoc-template.rb, TITLE=\"Custom Title\")" end
虽然,在这一点上,从命令行运行这样的东西似乎更容易:
rdoc --main README.md --title 'My Fancy Title' README.md app/**/*.rb lib/**/*.rb
This functionality was removed from Rails in version 5 with the following justification:
...In our experience applications do not generate APIs using doc:app...If a team absolutely needs to generate application documentation for internal purposes, they can still easily write their own task...
The functionality can be easily restored by creating a file at /lib/tasks/documentation.rake with the following contents, taken from the last version of the official task:
# /lib/tasks/documentation.rake require 'rdoc/task' namespace :doc do RDoc::Task.new("app") { |rdoc| rdoc.rdoc_dir = 'doc/app' rdoc.template = ENV['template'] if ENV['template'] rdoc.title = ENV['title'] || 'Rails Application Documentation' rdoc.options << '--line-numbers' rdoc.options << '--charset' << 'utf-8' rdoc.rdoc_files.include('README.md') rdoc.rdoc_files.include('app/**/*.rb') rdoc.rdoc_files.include('lib/**/*.rb') } Rake::Task['doc:app'].comment = "Generate docs for the app -- also available doc:rails, doc:guides (options: TEMPLATE=/rdoc-template.rb, TITLE=\"Custom Title\")" end
Although, at this point it almost seems easier to just run something like this, from the command line:
rdoc --main README.md --title 'My Fancy Title' README.md app/**/*.rb lib/**/*.rb
相关问答
更多-
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: items: SELECT "items".* FROM "items" 从错误消息中可以看出,现在数据库中不存在items表。 即使你没有故意删除它,它也会以某种方式被删除。 因此,您应该通过运行相应的迁移来再次创建items表: bundle exec rake db:migrate 更新 检查运行此rake任务的RAILS_ENV 。 当错误显示时,这意味着您 ...
-
此功能已从版本5中的Rails中删除,具有以下理由: ...根据我们的经验,应用程序不使用doc:app生成API ...如果团队绝对需要为内部目的生成应用程序文档,他们仍然可以轻松编写自己的任务... 通过在/lib/tasks/documentation.rake中创建一个文件,可以轻松恢复该功能,其中包含以下内容,取自官方任务的最新版本 : # /lib/tasks/documentation.rake require 'rdoc/task' namespace :doc do RDoc::Ta ...
-
对于本地计算机,在database.yml的test和development部分下,您应该将username更改为您登录的用户名。 导轨生成器使其与应用程序名称相同 - 这不起作用。 对于生产而言,它在Heroku上运行并不重要,并且在部署时会自动更改该设置。 For your local machine, under the test and development sections in database.yml you should change username to your logged in ...
-
是..你可以添加它自动加载,但另一种方法是通过“require”在rake文件中添加 这是另一种方式, LIB /电子表格/ importer.rb module Spreadsheet class Importer def initialize @session = GoogleDrive.saved_session("#{Rails.root}/config/google_drive/config.json") end def exec(ta ...
-
尝试这个 Post.delete_all(['created_at < ?', 7.days.ago]) Try this Post.delete_all(['created_at < ?', 7.days.ago])
-
似乎你的应用程序需要宝石rush [http://rubygems.org/gems/rush],这是缺失的。 按照网址进行安装,然后重试。 是的, bundle install应确保在系统中安装所有必需的gem。 gem install rush ,works或者添加gem rush到你的gem文件,然后运行bundle install(如果你使用bundler) Seems your application requires the gem rush [http://rubygems.org/gems/ ...
-
经过精炼搜索后,我能够找出错误。 在我的gemset中我有两个版本mongoid(2.x,3.x)。 所以,我删除了旧版本并添加了 我的lib / tasks文件夹中的Mongoid Rake文件解决了我的问题。 After a refine search I am able to figure out my error. In my gemset I have two versions mongoid(2.x,3.x). So, I removed the older version and added ...
-
耙子流产了! NoMethodError:场地的未定义方法`misc_info':0x007ff593140ee8您的意思是? misc_info_raw 正如我所说,你misc_info中缺少misc_info列。 添加它应该可以解决问题。 rake aborted! NoMethodError: undefined method `misc_info' for Venue:0x007ff593140ee8 Did you mean? misc_info_raw As I said, you are mi ...
-
测试任务从rake中丢失:rake中止!(Test tasks missing from rake: rake aborted! Don't know how to build task 'test:units')[2022-12-29]
看一看config/application.rb ,测试框架是否真的在那里需要。 在最顶端,应该有 require "rails/all" 根据您的设置,您可能需要分别单独安装每个组件。 确保其中test_unit 。 require "rails/test_unit/railtie" Take a look into config/application.rb whether the testing framework is actually required there. At the very ... -
耙子流产了!(rake aborted! ActionView::Template::Error: undefined method 'challenges' for nil:NilClass)[2021-12-19]
请更新您的佣金任务 task monthly_report: :environment do User.all.each do |user| if user.email.present? && user.challenges.present? && user.challenges.any? UserMailer.monthly_report(user).deliver_now end end end 如果您的用户没有在记录中有任何电子邮件,我认为错误提升试试这个 P ...