A convenient way to do this in server-side JavaScript is to wrap your processing logic into the before form event of a form, and then run that form in parallel using a separate java thread for each execution.
For example:
Code: Select all
importPackage(com.ebasetech.xi.api);
importPackage(com.ebasetech.xi.services);
// packages for calling HTTP and Thread
importPackage(java.io);
importPackage(java.net);
importPackage(java.lang);
// define an object containing a run method
var m = function(param) {
// define a URL to run an Ebase form, passing in a parameter
var url = "http://localhost:3030/ufs/ufsmain?formid=THREAD_TEST&PARAM1="+param;
// define the run method
this.run = function() {
// run the form passing in a parameter
try {
var myurl = new URL(url);
var con = myurl.openConnection();
var ins = con.getInputStream();
}
catch (e) {}
finally {con.disconnect;}
}
}
// run the form in 10 seperate threads
for (var i=0; i<10; i++) {
var r1 = new java.lang.Runnable(new m(i));
new java.lang.Thread(r1).start();
}
The parameter gets tacked on to the end of a URL to run an Xi form. The run() method simply makes an HTTP call using the form URL, which causes the form to execute.
We then loop from 0 to 9, creating a new thread to execute the form separately for each loop value, i.e. by passing in a new instance of our object with the loop value as a parameter.
The thread automatically executes whatever's defined inside the run() method and ends as soon as the method completes.
In the example we're calling a local form but there'd be nothing to stop you calling a form in another Xi instance.
NB. If you do want to do this then you will need to set
Code: Select all
Ufs.skipBrowserAttributesCheck=true