egambrell's picture

Hi -

I've created an import script that creates/updates objects from Excel. I would like to make this run faster with threads, but I can't get the code working.

 

This page was my reference: https://crunchify.com/how-to-run-multiple-threads-concurrently-in-java-executorservice-approach/

 

Does anyone know how to do something like this within the context of the ARIS API? Here is a sample script I was trying:

 

 

var log = "";

function main() {
var MYTHREADS = 4;
var executor = new java.util.concurrent.Executors.newFixedThreadPool(MYTHREADS);
var objectNames = ["Object 1", "Object 2", "Object 3", "Object 4"];

for (var i in objectNames) {
var objName = objectNames[i];
var worker = new MyRunnable(objName);
executor.execute(worker);
}

executor.shutdown();
// Wait until all threads are finish
while (!executor.isTerminated()) {

}
Dialogs.MsgBox("\nFinished all threads");
}

function MyRunnable(objName) {
this.objName = objName;

this.run = function() {
var result = "";
try {
var oObjDef = ArisData.getActiveDatabase().RootGroup().CreateObjDef(Constants.OT_FUNC, this.objName, 1033);
} catch (e) {
result = "->Red<-\t";
}
log += this.objName + " created\n";
}
}

main();