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();
I also need this, for the purpose of running a high volume of automated consolidations. Every consolidation between two objects takes 30seconds+, and processing 14,000 objects that have one duplicate each is taking many, many hours, with an under-utilized server CPU load between 4-10% ...
The Java way of multi-threading will most definitely not work, simply because Javascript-Engines were never made to handle those operations.
I'll say it right here upfront: I have no idea whether or not ARIS reports support multi threading. That being said there are two things I want to mention here:
- Your under-utilized ARIS server CPU probably does not reflect the overall system load. The ARIS server is communicating with a SQL database server, and a lot of the requests being made require answers from the SQL database server (not only those requests where you tell ARIS to look something up, like a list of models from a group, but also whether or not sql-database-write-operations were successful). There is simply a limit to how fast a SQL database can process requests, and it will most definitely process write-operations in sequential order to not mess things up.
- Multithreading in Javascript is done with things called "Web Worker". They are part of the HTML 5 standard and may not be available in the ARIS Script engine. This is knowledge I have made use of when I dipped into web-developing to widen my Javascript knowledge and therefore I can't tell whether or not it works in ARIS. If you really think you have operations that can be processed faster with multi threading, without messing up anything in your SQL database, go ahead and give it a try, I myself will stay away from it until Software AG says "this is how you do multi threading: [explanation expected]". You can just look up "HTML 5 Web worker" on the world wide web to find out more about them.