1 22 package org.jboss.test.jca.mbean; 23 24 import org.jboss.system.ServiceMBeanSupport; 25 26 34 public class MTTest extends ServiceMBeanSupport 35 implements MTTestMBean 36 { 37 public void testMTOperations(String test, MTOperation[][] ops) throws Exception 38 { 39 log.info("*** Starting test: " + test); 40 MTOperation.init(log); 41 42 int numOfThreads = ops.length; 45 log.info("Number of Threads: " + numOfThreads); 46 47 Thread [] threads = new Thread [numOfThreads]; 48 ExecTask[] tasks = new ExecTask[numOfThreads]; 49 for (int i = 0; i < numOfThreads; i++) 50 { 51 tasks[i] = new ExecTask(i, ops[i]); 52 threads[i] = new Thread (tasks[i]); 53 threads[i].start(); 54 } 55 56 Exception caughtException = null; 59 for (int i = 0; i < numOfThreads; i++) 60 { 61 try 62 { 63 threads[i].join(); 64 if (tasks[i].exception != null) 65 { 66 caughtException = tasks[i].exception; 69 } 70 } 71 catch (InterruptedException e) 72 { 73 i--; 75 } 76 } 77 log.info("*** Finished test: " + test); 78 MTOperation.destroy(); 79 80 if (caughtException != null) 81 { 82 throw caughtException; 83 } 84 } 85 86 private class ExecTask implements Runnable 87 { 88 int threadId; 89 MTOperation[] ops; 90 Exception exception; 91 92 public ExecTask(int threadId, MTOperation[] ops) 93 { 94 this.threadId = threadId; 95 this.ops = ops; 96 } 97 98 public void run() 99 { 100 log.info("Starting thread: " + Thread.currentThread().getName()); 101 try 102 { 103 for (int i = 0; i < ops.length; ++i) 104 { 105 ops[i].perform(); 106 } 107 } 108 catch (Exception e) 109 { 110 exception = e; 111 } 112 finally 113 { 114 log.info("Finished thread: " + Thread.currentThread().getName()); 115 } 116 } 117 } 118 } 119 | Popular Tags |