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