首页 \ 问答 \ 在ExecutorService的提交和ExecutorService的执行之间进行选择(Choose between ExecutorService's submit and ExecutorService's execute)

在ExecutorService的提交和ExecutorService的执行之间进行选择(Choose between ExecutorService's submit and ExecutorService's execute)

我在想,我应该如何选择ExecutorService的 提交或执行 ,如果返回的值不是我的关注? 如果我测试两者,除了返回的值之外,我没有看到任何差异。

ExecutorService threadExecutor = Executors.newSingleThreadExecutor();
threadExecutor.execute(new Task());

ExecutorService threadExecutor = Executors.newSingleThreadExecutor();
threadExecutor.submit(new Task());

How should I choose between ExecutorService's submit or execute, if the returned value is not my concern?

If I test both, I didn't see any differences among the two except the returned value.

ExecutorService threadExecutor = Executors.newSingleThreadExecutor();
threadExecutor.execute(new Task());

ExecutorService threadExecutor = Executors.newSingleThreadExecutor();
threadExecutor.submit(new Task());

原文:https://stackoverflow.com/questions/3929342
更新时间:2023-10-14 12:10

最满意答案

你猜到了。
使用pack模板,并“简化”一点:

template <typename...> struct pack {}; // To be potentially introduced in C++1Z

template <typename, typename, typename=void>
struct Exists_impl : std::false_type {};

template <typename R, typename... Args>
struct Exists_impl<R, pack<Args...>,
  std::enable_if_t<std::is_same<decltype(foo(std::declval<Args>()...)), R>::value>>
    : std::true_type {};

template <typename R, typename... Args>
using Exists = Exists_impl<R, pack<Args...>>;

演示
请注意,此模板永远无法通过ADL查找void(int)等函数,因为在这种情况下,关联的命名空间集合为空。 必须在定义时声明这些函数。
使用is_convertible而不是is_same来检查返回类型也是可行的,具体取决于用例。


You guessed it.
Use a pack template, and "simplify" a bit:

template <typename...> struct pack {}; // To be potentially introduced in C++1Z

template <typename, typename, typename=void>
struct Exists_impl : std::false_type {};

template <typename R, typename... Args>
struct Exists_impl<R, pack<Args...>,
  std::enable_if_t<std::is_same<decltype(foo(std::declval<Args>()...)), R>::value>>
    : std::true_type {};

template <typename R, typename... Args>
using Exists = Exists_impl<R, pack<Args...>>;

Demo.
Note that this template will never be able to find functions like void(int) via ADL, as the set of associated namespaces is empty in such cases. Those functions must be declared at the point of definition.
Also it might be feasible to use is_convertible instead of is_same for the check of the return type, depending on the use-case.

相关问答

更多
  • 要防止图像偏离右边缘,您需要计算其x坐标可以具有的最大值,并确保永远不会超出该值。 所以在循环之前创建一个带有值的变量: CAT_RIGHT_LIMIT = WINDOWWIDTH - catImg.get_width() 然后在循环中检查它: if catx >= CAT_RIGHT_LIMIT: moveRight = False catx = CAT_RIGHT_LIMIT if moveRight == True: catx += 5 当然,您可以将这个想法扩展到所有其他 ...
  • 你猜到了。 使用pack模板,并“简化”一点: template struct pack {}; // To be potentially introduced in C++1Z template struct Exists_impl : std::false_type {}; template struct Exists_impl
  • 我不知道它为什么会丢失(可能是因为模块是完全独立的,编译一个并不依赖于另一个 - 但这只是猜测)。 但我相信你可以通过透析器静态分析发现这样的问题。 看看http://www.erlang.org/doc/man/dialyzer.html 它是系统本身的一部分,所以请尝试将其包含在工作流程中。 I don't know why it's missing (probably because modules are completely separate and compilation of one does ...
  • 时间序列通常是你想要的:学习渐变,检测突然变化。 否则,时间起不到什么作用。 您可以尝试使用例如SigniTrend模型,学习速度非常慢(半衰期很长或者他们称之为它。忽略该论文中的所有令牌,散列和可扩展性,只获得我真正喜欢的EWMA + EWMVar部分和在你的时间序列中使用它)。 如果您将学习率设置得非常低,则阈值应该移动得足够慢,以便您的“渐进”更改仍然可以触发它们。 或者你完全忽视时间。 将您的数据拆分为训练集(不得包含异常),了解其中的均值和方差以查找阈值。 然后将这些阈值之外的任何点分类为异常(即 ...
  • PackageManager pm = getPackageManager(); List activities = pm.queryIntentActivities(new Intent( RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); if (activities.size()>0); // then you have SPEECH RECOGNIZER. 要么 final LocationManager ...
  • 由于Javascript没有编译,并且动态类型化,因此除了运行时之外,没有办法在您的示例中强制执行合约。 但是,您可以使用诸如Typescript,Flow等构建系统来为代码添加类型注释。 这些需要编译步骤但是在您的示例中您遇到的问题将在该步骤中被两者捕获。 没有这些,就我所知,没有办法得到你想要的东西。 你可以在vanilla javascript中做的最好的事情是验证你在localize函数中给出的参数,并使用日志/错误,以便在本地测试代码时轻松识别问题。 这里重要的一点是,如果没有实际运行代码,就无法 ...
  • 无论是否存在障碍物,都会进行碰撞检测。 您应该添加obstacles.exists作为碰撞测试的第一个测试: if (obstacles.exists and obstacles.x < player.x + player.w and obstacles.x + obstacles.w > player.x and obstacles.y < player.y + player.h and obstacles.h + obstacles.y ...
  • 设f为原始图像, g为过滤后的图像, h应用于f的过滤器,以便: f * h = g 将其传递到频域: F.H = G, so H = G/F 问题是反转F对噪声非常敏感。 如何在MATLAB中实现: close all; f = imread('cameraman.tif'); [x,y] = size(f); figure,imshow(f); h = fspecial('motion', 20, 40); % abitrary filter just for testing the algorit ...
  • 当您处理状态为“有A,需要B”而其他一些进程处于“有B,需要A”时,会发生死锁。 如果我正确地读你的表,那么这将表明一个僵局: Allocation Request Available A B C A B C A B C P0 0 1 0 1 0 0 0 0 0 P1 2 0 0 2 1 2 P0具有资源B,并且需要资源A,没有更多资源A可用 P1有2个资源A,需要源B,没有更多的B可用。 在更多资源A ...
  • 首先, particles[a] === particles[b]意味着,并且只有在a === b时才能为真 其次,当particles[a] === particles[b]增加b时,for循环再次增加b ...意味着你错过了粒子! 试试这个: for(var b = 0; b < particles.length; b++) { if(a === b) { continue; } else if(particles[a][3]+10 > particles[b][ ...

相关文章

更多

最新问答

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