In one of my goals I'm trying to exec multiple copies of a program
that will send test data to my server at the same time. I plan to
invoke the program once for each name in a property list, using that
name to determine where to find the data. I want to wait for all
copies of the program to finish before I continue.

I know how to process the list at runtime, but I'm having trouble with
the threads. After Googling the Internet, searching the Jelly lists,
and looking through source code, I still can't get it to work. If
anyone has done this, would you please give me some pointers. Here are
some examples of what I've tried so far, and why they are not working:

Jelly thread taglib
-------------------
This will create and wait for the threads, but since threads:group
gathers up all threads before invoking them, the value of ${type} for
every thread is the last item in dataList:

  <util:tokenize var="dataList" delim="," trim="true">
    ${interfaces}
  </util:tokenize>
  <j:new var="ran" className="java.util.Random"/>
  <threads:group var="feeds">
    <j:forEach var="type" items="${dataList}">
      <threads:thread name="${type}Name" var="${type}Var">
        <j:set var="i" value="${(ran.nextInt(5)+1)*1000}"/>
        <ant:echo>${type}: sleeping for ${i} millisecond</ant:echo>
        <util:sleep millis="${i}"/>
        <ant:echo>${type}: done</ant:echo>
      </threads:thread>
    </j:forEach>
  </threads:group>
  <ant:echo>Waiting on threads: ${feeds}</ant:echo>
  <threads:waitFor group="${feeds}"/>
  <ant:echo>All threads have finished</ant:echo>

I also tried invoking the threads without the thread group, then going
through the same forEach loop and using threads:waitFor or
threads:join for each thread. In both cases, that gives the error
message "Property 'thread' has no write method".

Ant parallel and sequential tasks
---------------------------------
This lets me get a different ${type} per thread, but the threads get
invoked sequentially, even when within the parallel tag:

  <util:tokenize var="dataList" delim="," trim="true">
    ${interfaces}
  </util:tokenize>
  <j:new var="ran" className="java.util.Random"/>
  <ant:parallel>
    <j:forEach var="type" items="${dataList}">
      <ant:sequential>
        <j:set var="i" value="${(ran.nextInt(5)+1)*1000}"/>
        <ant:echo>${type}: sleeping for ${i} millisecond</ant:echo>
        <util:sleep millis="${i}"/>
        <ant:echo>${type}: done</ant:echo>
      </ant:sequential>
    </j:forEach>
  </ant:parallel>
  <ant:echo>Waiting on threads</ant:echo>
  <ant:echo>All threads have finished</ant:echo>

I thought the above loop would be the same as doing something like:

  <parallel>
    <sequential/>
        ...
    <sequential/>
  </parallel>

but apparently it's not. If anyone can give me some more ideas to
investigate, I'd appreciate it.

    Jeff

-- 
mailto:[EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to