private void execute(String serviceId) throws Exception { Registry r = buildFrameworkRegistry("ServiceModelThreading.xml", false); Worker w = (Worker) r.getService(serviceId, Worker.class); Thread threads[] = new Thread[THREAD_COUNT]; RunnableManager managers[] = new RunnableManager[THREAD_COUNT]; RunnableFixture fixture = new RunnableFixture(); for (int i = 0; i < THREAD_COUNT; i++) { managers[i] = new RunnableManager(r, w, fixture); threads[i] = new Thread(managers[i], "Worker #" + (i + 1)); } for (int i = 0; i < THREAD_COUNT; i++) threads[i].start(); // Let the rest do their thing Thread.yield(); for (int i = 0; i < THREAD_COUNT; i++) { try { threads[i].join(JOIN_WAIT); } catch (InterruptedException ex) { } } assertEquals( "Number of executions of the RunnableFixture", THREAD_COUNT * ITERATIONS, fixture.getInvokeCount()); }
public void run() { for (int i = 0; i < ITERATIONS; i++) { _worker.run(_runnable); _registry.cleanupThread(); } _completed = true; }