首页 \ 问答 \ 我如何知道Fork和Join在Java中的池大小是否足够?(How do I know if Fork and Join has enough pool size in Java?)

我如何知道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
更新时间:2023-08-17 09:08

最满意答案

此功能已从版本5中的Rails删除,具有以下理由:

...根据我们的经验,应用程序不使用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 

相关问答

更多

相关文章

更多

最新问答

更多
  • 延迟socket.io响应,并“警告 - websocket连接无效”(Delayed socket.io response, and “warn - websocket connection invalid”)
  • IIS 7.5仅显示homecontroller(IIS 7.5 only shows homecontroller)
  • 我如何删除ListView中的项目?(How I can remove a item in my ListView?)
  • 武陟会计培训类的学校哪个好点?
  • Spring事务管理:无法解析bean'transactionManager'的引用(Spring transaction management: Cannot resolve reference to bean 'transactionManager')
  • 无法在后面访问链接:焦点,移开,div(Link can't be accessed behind :focus, moved out of the way, div)
  • 总和形式选择值 - 我做错了什么(sum form select values - what am I doing wrong)
  • DocBook5 ISO 690参考书目的文档[关闭](Documentation for DocBook5 ISO 690 bibliography [closed])
  • 为什么改变所有点的颜色而不是一个?(Why changed the color for all points instead of one?)
  • 如何从字符串中删除所有尾部破折号?(How can I remove all trailing dashes from a string?)
  • 有没有办法以这种方式调用这个JavaScript函数?(is there a way to call this javascript function in this way?)
  • 在更换字符串时替换组(Replacing a group while replacing a string)
  • 如何用Dreamweaver制作网页表格
  • git:如何能够再次切换分支(git: how to be able to switch branches again)
  • 应用程序在打印联系人姓名和号码时崩溃(app crashes in the middle of printing contact names and numbers)
  • 用CSS @media查询目标移动设备解决方案的最准确的方法是什么?(what is the most accurate way to query target mobile device resolutions with CSS @media?)
  • Java - 如何仅使元音加倍(Java - How to double only Vowels)
  • 调用root.destroy()后出现“tkinter.TclError:invalid command name”错误(“tkinter.TclError: invalid command name” error after calling root.destroy())
  • 使用键绑定在两个表单之间切换(Switching between two forms with Key Bindings)
  • 我把正确的导入但错误仍然发生在Hibernate 5中的org.hibernate.MappingException(I put the correct import but the error still happen org.hibernate.MappingException in Hibernate 5)
  • 从宁波江北洪塘到宁波南站人力市场乘坐什么车子要转什么车子,我去人力市场考电工上岗证
  • jQuery - 用所有元素的新值替换属性值(jQuery - replace attribute value with new value of all elements)
  • Lenovo Low Profile USB Keyboard 下载后找不到电脑上没有
  • 将反应元素渲染到隐藏区域以进行测量(Render a react element to a hidden area for measurement)
  • 有没有可能确定iOS widget何时隐藏?(Is it possible to determine when iOS widget hides?)
  • 量角器 - 描述没有定义(Protractor - describe is not defined)
  • Jackson序列化:XML和JSON的不同格式(Jackson Serialization: Different formats for XML and JSON)
  • 在Javascfipt中解析XML(Parsing XML in Javascfipt)
  • Firebird客户端安装(Firebird client installation)
  • 在未安装XML DB的情况下从Oracle发送电子邮件(Send email from Oracle without XML DB installed)