java中通过继承Thread创建线程,程序为什么不能同时进行?结果如下
[code=java]publicclassRunner{publicstaticvoidmain(String[]args){runnerr=newrunner();r...
[code=java]
public class Runner
{
public static void main(String[] args)
{
runner r = new runner();
r.start();
for (int i = 0; i < 50; ++i)
System.out.println(i);
}
}
class runner extends Thread
{
public void run()
{
for (int i = 0; i < 50; ++i)
System.out.println("thread"+i);
}
}
[/code]
结果:
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
thread0
thread1
thread2
thread3
thread4
thread5
thread6
thread7
thread8
thread9
thread10
thread11
thread12
thread13
thread14
thread15
thread16
thread17
thread18
thread19
thread20
thread21
thread22
thread23
thread24
thread25
thread26
thread27
thread28
thread29
thread30
thread31
thread32
thread33
thread34
thread35
thread36
thread37
thread38
thread39
thread40
thread41
thread42
thread43
thread44
thread45
thread46
thread47
thread48
thread49 展开
public class Runner
{
public static void main(String[] args)
{
runner r = new runner();
r.start();
for (int i = 0; i < 50; ++i)
System.out.println(i);
}
}
class runner extends Thread
{
public void run()
{
for (int i = 0; i < 50; ++i)
System.out.println("thread"+i);
}
}
[/code]
结果:
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
thread0
thread1
thread2
thread3
thread4
thread5
thread6
thread7
thread8
thread9
thread10
thread11
thread12
thread13
thread14
thread15
thread16
thread17
thread18
thread19
thread20
thread21
thread22
thread23
thread24
thread25
thread26
thread27
thread28
thread29
thread30
thread31
thread32
thread33
thread34
thread35
thread36
thread37
thread38
thread39
thread40
thread41
thread42
thread43
thread44
thread45
thread46
thread47
thread48
thread49 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询