JMeter-- ThreadGroup原理分析
JMeterEngine会驱动JMeter ThreadGroup启动Test Threads 执行测试,其本身也是一个Runnable,这里把测试驱动(JUnit或者其他类似main之类的)看作主线程(main thread)的话, JMeterEngine作为第一层子线程(First Child Thread),所以如果项目代码基于很多模块(比如基于OSGI),需要进行ClassLoader调整的话可以重写JMeterEngine的runTest方法,例如.:
public void runTest() throws JMeterEngineException { try { tcClassloader = Thread.currentThread().getContextClassLoader(); Future<?> f = DefaultExecutorService.getInstance().submit(this); f.get(); } catch (Exception err) { stopTest(); throw new JMeterEngineException(err); } finally { } } @Override public void run() { ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(tcClassloader); try { super.run(); } finally { Thread.currentThread().setContextClassLoader(oldCl); } }
记下自己的成长笔记,积跬步以成千里。知识额无穷尽矣!--Alter