如何重置multithreading任务? (JXcore)

我有一个node.js应用程序,我已经进入JXcoremultithreading,但无法弄清楚如何重置任务。 在当前实现中,服务器创build一个subprocess并逐个发送作业。

当工作超过X秒时,主进程杀死subprocess并跳过正在运行的任务并logging。 任何工作不应超过X秒。

到目前为止,我已经将队列系统轻松地移入JXcore,并且按预期工作,但是我还没弄明白,我怎么才能杀死正在运行的任务。

看起来杀死正在运行的任务的能力是一个需要的function,因为有人已经问过同样的问题,并已在这里回答: 线程生命周期pipe理 。

即将推出的JXcore版本将有jxcore.tasks.killThread() 。 逻辑是这样的:一个任务会通知主线程,它刚刚启动,然后主线程可能会开始计算线程的超时时间,例如:

 // main thread receives the message from a task jxcore.tasks.on("message", function(threadId, obj){ if(obj.started){ //kill the task after a second setTimeout(function(){ jxcore.tasks.killThread(threadId); console.log("thread killed", threadId); },1000); } }); // adding a task jxcore.tasks.addTask( function() { // informing the main thread, that task is just started process.sendToMain({started:true}); // looping forever while(true){}; console.log("this line will never happen."); });