Jxcore add new task parallel -
i'm using jxcore execute job in parallel. when test below
var method = function () { var sleep = require('sleep'); console.log("thread started", process.threadid); sleep.sleep(2); console.log("thread finished", process.threadid); }; jxcore.tasks.addtask(method); jxcore.tasks.addtask(method); jxcore.tasks.addtask(method); jxcore.tasks.addtask(method);
result seems 1 thread used :
thread started 0 thread finished 0 thread started 0 thread finished 0 thread started 0 thread finished 0 thread started 0 thread finished 0
i expect , create 4 thread start parallel. how can achieve ?
try:
function.prototype.clone = function() { var = this; var temp = function temporary() { return that.apply(this, arguments); }; for(var key in this) { if (this.hasownproperty(key)) { temp[key] = this[key]; } } return temp; }; var method = function () { var sleep = require('sleep'); console.log("thread started", process.threadid); sleep.sleep(2); console.log("thread finished", process.threadid); }; jxcore.tasks.addtask(method); jxcore.tasks.addtask(method.clone()); jxcore.tasks.addtask(method.clone()); jxcore.tasks.addtask(method.clone());
or:
var newmethod1 = method.clone(); jxcore.tasks.addtask(newmethod1); jxcore.tasks.runonce(newmethod1);
Comments
Post a Comment