Cernunnos Manual


<thread-pool>

Description:

Creates a thread pool (ExecutorService) with a default size of 4 threads and stores it in a request attribute named 'ConcurrentAttributes.EXECUTOR_SERVICE' by default. The task will wait for all tasks in the thread pool to complete before completing itself.

Use a <concurrent> task within this task.

Reagents:

Name XPath Description Reagent Type Expected Type Required
ATTRIBUTE_NAME @attribute-name Optional name under which the new ExecutorService will be registered as a request attribute. If omitted, the name 'ConcurrentAttributes.EXECUTOR_SERVICE' will be used. PHRASE java.lang.String No
THREADS @threads Number of threads to use in the thread pool, defaults to 4. PHRASE java.lang.String No
QUEUE_RATIO @queue-ratio Number of tasks to queue per thread, defaults to 10. PHRASE java.lang.String No
USE_EXISTING @use-existing If true an ExecutorService that already exists for the specified attribute name will be used instead of creating a new ExecutorService. Defaults to false. PHRASE java.lang.String No
SUBTASKS * The set of tasks that are children of this task. NODE_LIST java.util.List No

Examples:

Creates an array of three URLs in JavaScript, then computes a checksum value ten times for one of the URLs in the array (distributed evenly) using a pool of five threads, writing the current count and checksum value to the console each time:

 
       
        <js> 
          <script>var urls = ['http://www.google.com/', 'http://www.amazon.com/', 'http://www.yahoo.com/']; ScriptAttributes.RESPONSE.setAttribute('urls', urls);</script>  
          <subtasks> 
            <thread-pool threads="5"> 
              <for-each attribute-name="num" items="${groovy([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])}"> 
                <concurrent> 
                  <echo-ln>${num}=${checksum(${js(urls[num % 3])})}</echo-ln> 
                </concurrent> 
              </for-each> 
            </thread-pool> 
          </subtasks> 
        </js>