执行者服务中断处理(executor Service interupt handling)
我有一个应用程序,其中有多个线程。 我希望它们按顺序执行,所以我选择executorService进行多线程。 如果任何一个线程(运行方法)出错,我想转到网络线程,以便最终我可以知道有多少线程成功完成(需要计数)。我的示例代码:
主要课程:
public class MySampleClass{ ExecutorService executor = Executors.newSingleThreadExecutor(); for(int i=0; i<=100;i++){ executor.submit(new ThreadClass()); } //After all threads executed now to shutdown executor executor.shutdown() executor.awaitForTermination(1,Time.MILLISECONDS);
我的示例线程类:
public class ThreadClass implements Runnable{ @override public void run(){ boolean isCompleted= doAction(); if(!isCompleted){ // I want here to stop this thread only..what to do ? //executor.shutdown will stop all other threads } } }
任何建议怎么办? 我做错了吗?
I have an application in which there are multiple threads. I want them to execute in order.so i choose executorService for multi-threading. if any one of thread(run method) is in error , I want to move on to net thread so that by the end i can come to know how many thread are completed successfully (count needed).My sample code:
The Main class:
public class MySampleClass{ ExecutorService executor = Executors.newSingleThreadExecutor(); for(int i=0; i<=100;i++){ executor.submit(new ThreadClass()); } //After all threads executed now to shutdown executor executor.shutdown() executor.awaitForTermination(1,Time.MILLISECONDS);
My Sample Thread Class :
public class ThreadClass implements Runnable{ @override public void run(){ boolean isCompleted= doAction(); if(!isCompleted){ // I want here to stop this thread only..what to do ? //executor.shutdown will stop all other threads } } }
Any Suggestion what to do ?? Am i doing it wrong way ?
原文:https://stackoverflow.com/questions/41747648
最满意答案
是的,你可以做到这一点。
由于您使用的是Durandal.router,因此您可以通过覆盖路由器autoConvertRouteToModuleId来使用查找ViewModel的约定,如下所示:
router.autoConvertRouteToModuleId = function(url, params) { return url + '/' + 'params[0]'; };
至于找到绑定到您的viewmodel的视图,那么您可以像上面那样..更改viewlocator约定。
yes you can do this.
Since you are using Durandal.router you can use a convention of where to find your ViewModels by overriding the routers autoConvertRouteToModuleId like so:
router.autoConvertRouteToModuleId = function(url, params) { return url + '/' + 'params[0]'; };
As for finding the view that binds to your viewmodel then you can like you have above.. change the viewlocator convention.
相关问答
更多-
DurandalJS路由行为(DurandalJS Routing Behavior)[2022-08-01]
由于某种原因,我怀疑调用navigateTo可能会过早。 要测试这个理论,请尝试移动此代码。 if (dataservice.isAuthenticated() === true) { app.setRoot('viewmodels/shell', 'entrance'); router.navigateTo('home'); } else { app.setRoot('viewmodels/public'); router.n ... -
Durandaljs可以做区域(Can Durandaljs do Areas)[2024-04-24]
是的,你可以做到这一点。 由于您使用的是Durandal.router,因此您可以通过覆盖路由器autoConvertRouteToModuleId来使用查找ViewModel的约定,如下所示: router.autoConvertRouteToModuleId = function(url, params) { return url + '/' + 'params[0]'; }; 至于找到绑定到您的viewmodel的视图,那么您可以像上面那样..更改viewlocator约定。 yes you ... -
我想我明白了。 它并不像我希望的那样漂亮,但我很高兴能够重用对话框插件和转换机制。 这是我使用的对话框上下文: define(['jquery', 'knockout', 'transitions/entrance', 'plugins/dialog'], function ($, ko, entrance, dialog) { return { addHost: function (theDialog) { //Cheat - only applies to ...
-
我有一个非常相似的设置,我在子路由器上创建一个路由来表示这样的空白路由: var childRouter = router.createChildRouter().makeRelative({ moduleId: 'views/settings', fromParent: true }).map([ { route: '', moduleId: 'main', nav: true }, { route: 'users', moduleId: 'child/users/list', nav ...
-
我找到了一个非常简单的方法来做到这一点。 只需致电 location.reload I found a pretty easy way to do this. Simply call location.reload
-
我不确定哪一个是现在最好的选择...实际上我会说他们都没有足够的未来。 Angular 2.0将与1.0完全不同,当然也来自Durandal。 然而,框架本身可能并不那么重要。 我认为你应该专注于在可重用组件中分离代码。 无论是角色服务/工厂/提供商还是Durandal中的干净需求模块,它实际上都无关紧要。 进入“新”框架应该只是添加适当的包装器。 至于双向绑定使用oberserver插件来维护干净的POJO。 从我在NG2中的角度来看,最重要的变化将是生命周期事件的支持,所以即使在Durandal中使用它 ...
-
尝试使用另一个使li 显示 为 none的 css类,也许你有一个css规则覆盖li的显示 ,参见示例: .example-visible{ display:none !important; }
为什么在durandaljs中没有调用compositionComplete事件(Why is the compositionComplete event not called in durandaljs)[2023-06-19]
在您的第2步中,您没有self.compositionCompleted事件,因为您没有上下文'self' 你需要声明self = this; var self =this; self.name = whatever; self.compositionComplete In your step 2 you don't have a self.compositionCompleted event because you don't have a context 'self' You need to decl ...由于你的包装和缩小Durandal应用程序似乎没有对我的大小问题的确定答案,我想我会通过逐个缩小每个Durandal JavaScript文件进行* 粗略 *比较。 然后我们可以总结各个文件,以大致了解Durandal本身的大小。 以下是关于Durandal在尺寸方面可以添加到您的应用程序的一些指导原则: Durandal 1.2.0(约71Kb原料/ ~41Kb缩小) \迪朗达尔 app.js(缩小2,190字节/ 1,334字节) composition.js(10,536字节/ 6,177字节缩小) ...您可以使用viewLocator.useConvention - 可能是这样的: viewLocator.useConvention( "areas/area1/viewmodels", "areas/area1/views", "areas/area1/templates" ); 要实现的一件好事是useConvention()与任何现有的require.config paths设置一 ...相关文章
更多- Web Service PHP入门示例
- 关于Service常驻内存不被清理的解决方法.
- 使用init.rc启动项调试service
- OSGi Service 和 Bundle扩展点 的区别,谢谢大家
- Solr/Lucene escape char handling
- 把业务逻辑从Action层移到Service层遇到的麻烦,求解
- 用axis开发java web service中关于服务返回复杂类型的问题
- spring3MVC +spring security3 关于扩展UserDetailsService 无法注入service的疑问.
- RFC2848--The PINT Service Protocol: Extensions to SIP and SDP for IP Access to Telephone Call Services
- SSH中action到service的错误
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)