/* */ public void start()
/* */ {
/* 122 */ if (this.mRunner != null) {
/* 123 */ throw new RuntimeException("Instrumentation already started");
/* */ }
/* 125 */ this.mRunner = new InstrumentationThread("Instr: " + getClass().getName());
/* 126 */ this.mRunner.start();
/* */ }在第125行我们很明显知道新的线程名就叫做"Instr:android.test.InstrumentationTestRunner",因为这个方法是从子类android.test.InstrumentationTestRunner中传进来的,所以getClass().getName()方法获得的就是子类的名字。
我们继续看这个线程是如何建立起来的,继续进入InstrumentationThread这个Instrumentation的内部类:
/* */ private final class InstrumentationThread
/* */ extends Thread {
/* 1689 */ public InstrumentationThread(String name) { super(); }
/* */
/* */ public void run() {
/* */ try {
/* 1693 */ Process.setThreadPriority(-8);
/* */ } catch (RuntimeException e) {
/* 1695 */ Log.w("Instrumentation", "Exception setting priority of instrumentation thread " + Process.myTid(), e);
/* */ }
/* */
/* 1698 */ if (Instrumentation.this.mAutomaticPerformanceSnapshots) {
/* 1699 */ Instrumentation.this.startPerformanceSnapshot();
/* */ }
/* 1701 */ Instrumentation.this.onStart();
/* */ }
/* */ }从最前面的定义可看到该类是继承与Thread对象的,所以后面提供个重写的run方法来代表该线程的运行入口完成一个Thread线程的完整实现。1701行,Instrumentation.this得就是子类InstrumentationTestRunner的实例,那么它的onStart方法又做了什么事情呢?
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/ruanjian/article-26961-3.html
但对有损我国主权的行为