当前位置: 首页 > news >正文

兰州展柜公司网站建设线上销售平台有哪些

兰州展柜公司网站建设,线上销售平台有哪些,网页设计导航栏内容,i深圳app官方下载在我正在开发的框架中,用户可以选择在后台运行某个耗时的任务,同时做其他事情.该任务计算一系列结果.在某些时候,当他/她需要后台任务的结果时,可以等待一段时间,直到:> a)发生超时(在这种情况下,用户希望获得到目前为止计算的所有结果,如果存在的话);要么> b…

在我正在开发的框架中,用户可以选择在后台运行某个耗时的任务,同时做其他事情.该任务计算一系列结果.在某些时候,当他/她需要后台任务的结果时,可以等待一段时间,直到:

> a)发生超时(在这种情况下,用户希望获得到目前为止计算的所有结果,如果存在的话);要么

> b)达到最大数量或计算结果(正常结束),

以先发生者为准.

问题是:即使发生超时,用户仍然希望到目前为止计算结果.

我尝试使用Future< V> .get(long timeout,TimeUnit unit)和Callable< V>这样做了. -derived类,但是当发生TimeoutException时,它通常意味着任务过早完成,因此没有可用的结果.因此我不得不添加一个getPartialResults()方法(参见下面的DiscoveryTask),我担心这种用法对潜在用户来说太违反直觉了.

发现调用:

public Set discover(Integer max, long timeout, TimeUnit unit)

throws DiscoveryException

{

DiscoveryTask task = new DiscoveryTask(max);

Future> future = taskExec.submit(task);

doSomethingElse();

try {

return future.get(timeout, unit);

} catch (CancellationException e) {

LOG.debug("Discovery cancelled.", e);

} catch (ExecutionException e) {

throw new DiscoveryException("Discovery failed to execute.", e);

} catch (InterruptedException e) {

LOG.debug("Discovery interrupted.", e);

} catch (TimeoutException e) {

LOG.debug("Discovery time-out.");

} catch (Exception e) {

throw new DiscoveryException("Discovery failed unexpectedly.", e);

} finally {

// Harmless if task already completed

future.cancel(true); // interrupt if running

}

return task.getPartialResults(); // Give me what you have so far!

}

发现实现:

public class DiscoveryTask extends Callable>

implements DiscoveryListener

{

private final DiscoveryService discoveryService;

private final Set results;

private final CountDownLatch doneSignal;

private final MaximumLimit counter;

//...

public DiscoveryTask(Integer maximum) {

this.discoveryService = ...;

this.results = Collections.synchronizedSet(new HashSet());

this.doneSignal = new CountDownLatch(1);

this.counter = new MaximumLimit(maximum);

//...

}

/**

* Gets the partial results even if the task was canceled or timed-out.

*

* @return The results discovered until now.

*/

public Set getPartialResults() {

Set partialResults = new HashSet();

synchronized (results) {

partialResults.addAll(results);

}

return Collections.unmodifiableSet(partialResults);

}

public Set call() throws Exception {

try {

discoveryService.addDiscoveryListener(this);

discoveryService.getRemoteResources();

// Wait...

doneSignal.await();

} catch (InterruptedException consumed) {

LOG.debug("Discovery was interrupted.");

} catch (Exception e) {

throw new Exception(e);

} finally {

discoveryService.removeDiscoveryListener(this);

}

LOG.debug("Discovered {} resource(s).", results.size());

return Collections.unmodifiableSet(results);

}

// DiscoveryListener interface

@Override

public void discoveryEvent(DiscoveryEvent de) {

if (counter.wasLimitReached()) {

LOG.debug("Ignored discovery event {}. "

+ "Maximum limit of wanted resources was reached.", de);

return;

}

if (doneSignal.getCount() == 0) {

LOG.debug("Ignored discovery event {}. "

+ "Discovery of resources was interrupted.", de);

return;

}

addToResults(de.getResourceId());

}

private void addToResults(ResourceId id) {

if (counter.incrementUntilLimitReached()) {

results.add(id);

} else {

LOG.debug("Ignored resource {}. Maximum limit reached.",id);

doneSignal.countDown();

}

}

}

在Brian Goetz等人的Java Concurrency in Practice一书的第6章中,作者展示了相关问题的解决方案,但在这种情况下,所有结果都可以并行计算,这不是我的情况.确切地说,我的结果取决于外部来源,因此我无法控制它们何时到来.我的用户在调用任务执行之前定义了他想要的最大结果数,以及她在准备好获得结果后同意等待的最长时间限制.

这对你好吗?你会以不同的方式做吗?有没有更好的方法?

最佳答案 将(较短的)超时传递给任务本身,并在达到此“软超时”时提前返回.然后结果类型可以有一个标志,告诉结果是否完美:

Future future = exec.submit(new Task(timeout*.9));

//if you get no result here then the task misbehaved,

//i.e didn't obey the soft timeout.

//This should be treated as a bug

Result result = future.get(timeout);

if (result.completedInTime()) {

doSomethingWith(result.getData());

} else {

doSomethingElseWith(result.getData());

}

http://www.lbrq.cn/news/2443447.html

相关文章:

  • 百货商城网站建设网络营销是什么意思
  • wordpress和站点网页制作软件dreamweaver
  • 莱西网站建设公司企业网站建设方案
  • 历史价格查询百度seo关键词排名优化教程
  • 珠宝静态网站模板茂名seo顾问服务
  • 成都网上商城网站建设互联网推广招聘
  • 本网站建设广州网页推广公司
  • 网站设计方案及报价单湖南百度推广公司
  • 全球网站排名查询外贸软件
  • 算命网站建设开发沈阳seo按天计费
  • 织梦做的网站打包在dw修改友情链接的四个技巧
  • wordpress主题更改首页贵州seo技术查询
  • 网站标题写什么作用是什么网站推广优化价格
  • 网站建设合同封面网络营销是指
  • 个人网站免费模板seo外链友情链接
  • 学校网站模板html下载女孩子做运营是不是压力很大
  • 昆明定制化网站建设天津seo推广软件
  • 哈尔滨住房和城乡建设委员会网站百度app登录
  • 微信自己怎么弄小程序北京seo供应商
  • 酒泉如何做百度的网站经典软文广告
  • wordpress macos武汉seo网站优化排名
  • 如何建设一个商城网站搜索推广和信息流推广的区别
  • 做悬赏的网站网络营销专业是学什么的
  • 怎么建立一个网站csdn网络营销团队
  • 网站需要什么服务器seo企业培训班
  • 检测网站是用什么代码做的软件百度推广深圳分公司
  • 个人备案域名做企业网站广州网络推广定制
  • Wordpress自动回复评论昆明seo网站建设
  • 网站建设与熊掌号未来的关系百度游戏排行榜风云榜
  • 海原网站建设网站模板价格
  • 01人工智能中优雅草商业实战项目视频字幕翻译以及声音转译之底层处理逻辑阐述-卓伊凡|莉莉
  • 八股文Kafka学习
  • MySQL 8.0 OCP 1Z0-908 题目解析(37)
  • Zama+OpenZeppelin:将机密智能合约带入 DeFi 和数字资产领域
  • MongoDB数据库高并发商业实践优化·运行优化之不可使用root账户进行MongoDB运行-优雅草卓伊凡
  • Qt 多线程编程最佳实践