1 package org.oddjob.jobs.structural; 2 3 import java.util.Enumeration ; 4 import java.util.Vector ; 5 6 import org.oddjob.Stoppable; 7 import org.oddjob.framework.StructuralJob; 8 9 32 33 public class ParallelJob extends StructuralJob 34 implements Stoppable { 35 36 40 public void init() { 41 childHelper.initialise(); 42 } 43 44 53 public void addComponent(Object child) { 54 logger().debug("Adding child [" + child + "]"); 55 childHelper.addChild(child); 56 } 57 58 62 protected void execute() throws InterruptedException { 63 Vector jobThreads = new Vector (); 64 Object [] children = childHelper.getChildren(); 65 66 for (int i = 0; i < children.length; ++i) { 67 if (children[i] instanceof Runnable ) { 68 Thread t = new Thread ((Runnable ) children[i]); 69 jobThreads.add(t); 70 t.start(); 71 } 72 } 73 74 for (Enumeration elements = jobThreads.elements(); 75 elements.hasMoreElements() ;) { 76 Thread t = (Thread )elements.nextElement(); 77 t.join(); 78 } 79 } 80 } 81 | Popular Tags |