Metamerge logo
Search

Advanced Search
*
*
*
* HOME DOCUMENTS & RESOURCES DOWNLOADS EARLY TECH ACCESS SUPPORT FAQ KNOWN ISSUES OLD VERSIONS
*

 

Tasks

By convention all threads ( AssemblyLines, EventHandlers etc ...) are referred to as the "task" object. See task object.

The task object is the thread that executes the AssemblyLine. For each Connector in the AssemblyLine, there is a rscTaskComponent class encapsulating each Connector. Each Connector is automatically declared by their names (as given in the AssemblyLine configuration). Hence, name the Connector such that they are valid names in the selected scripting language.

See also the main object being the top level thread. This object has methods for manipulating AssemblyLines and querying status information.

How to Control the Number of Threads

(This section is for advanced users)

As stated above AssemblyLines and  EventHandlers both are threads.  Certain EventHandlers (such as TCP and HTTP) might even start a new thread for every new event they get.  Forking out lots of threads by letting AssemblyLines start lots of other AssemblyLines can cause you to run out of memory.

There are different ways of avoiding this, one of them being to wait for AssemblyLines to finish before you start a new one using the join() call : The code:

// Here we start the AssemblyLine itself 
var al = main.startAL ( "assemblyline", entry );
 // wait for al to finish 
al.join(); 
var result = al.getResult();

will do just  that: If you omit the al.join() call, the master AssemblyLine will continue without waiting (and might create new AssemblyLines)

Another way of limiting the number of threads you have is to use the function java.lang.Thread.activeCount() (and possibly java.lang.Thread.sleep() ).

activeCount() can be used to know the total number of threads in use by the thread group task belongs to.

For example, if the EventHandler checks how many threads are existing, it can sleep before starting new ones. Here is the Java code for the EventHandler to sleep 1000 milliseconds if you have started more than 20 threads which are still running. (Note that the Admin-tool and Server eat up some threads, so your activeCount starts around 4)

while (java.lang.Thread.activeCount() > 20)
    java.lang.Thread.sleep(1000);
main.startAL ( "assemblyline", entry );

If you wanted to start asynchronous AssemblyLines unless your thread count was high, you could say something like  

var al = main.startAL ("xxx");
main.logmsg ( 
    "Number of threads: " +
java.lang.Thread.activeCount() );
if (
java.lang.Thread.activeCount() > 20 )
    al.join();

 

 

*
  Metamerge Integrator version 4.6 ©Copyright Metamerge AS 2000-2002 Last edited 2002-06-10 contact us