本帖最后由 zl918 于 2012-1-14 10:41 编辑
- class MyThread implements Runnable {
- public void run() {
- for (int i = 0; i < 5; i++) {
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- }
- System.out
- .println(Thread.currentThread().getName() + "运行,i = " + i);
- }
- }
- };
- public class ThreadSleepDemo {
- public static void main(String args[]) {
- MyThread mt1 = new MyThread();
- Thread t1 = new Thread(mt1, "线程");
- t1.start();
- System.out.println("ThreadSleepDemo");
- }
- }
复制代码 在主方法中System.out.println("ThreadSleepDemo")在启动线程之后,但是运行结果是:
ThreadSleepDemo
线程运行,i = 0
线程运行,i = 1
线程运行,i = 2
线程运行,i = 3
线程运行,i = 4
先运行System后运行start方法。
为什么呢?
是System的优先级高吗?
该贴已经同步到 zl918的微博 |
|