62,615
社区成员
发帖
与我相关
我的任务
分享
public class Base extends Thread {
public static StringBuffer log=new StringBuffer();
private int i;
public void run()
{
for(i=1;i<=100;i++)
{
log.append( (Thread.currentThread()).getName()+":"+i+" ");
if(i%10==0)
{
log.append("\n");
}
}
}
public class Test {
public static void main(String[] args) throws Exception {
Base b1=new Base();
Base b2=new Base();
b1.setName("b1");
b2.setName("b2");
b1.setPriority(Thread.MAX_PRIORITY);
b2.setPriority(Thread.MIN_PRIORITY);
b1.start();
b2.start();
b1.join();
b2.join();
System.out.println(Base.log);
}
}
b1:1 b1:2 b1:3 b2:1 b1:4 b2:2 b1:5 b2:3 b1:6 b2:4 b1:7 b2:5 b1:8 b2:6 b1:9 b2:7 b1:10
b2:8 b1:11 b2:9 b1:12 b2:10
b1:13 b2:11 b1:14 b2:12 b1:15 b2:13 b1:16 b2:14 b1:17 b2:15 b1:18 b2:16 b1:19 b2:17 b1:20
b2:18 b1:21 b2:19 b1:22 b2:20
b1:23 b2:21 b1:24 b2:22 b1:25 b2:23 b1:26 b2:24 b1:27 b2:25 b1:28 b2:26 b1:29 b2:27 b1:30
b2:28 b1:31 b2:29 b1:32 b2:30
b1:33 b2:31 b1:34 b2:32 b1:35 b2:33 b1:36 b2:34 b1:37 b2:35 b1:38 b2:36 b1:39 b2:37 b2:38 b1:40
b2:39 b1:41 b2:40
b1:42 b2:41 b1:43 b2:42 b1:44 b2:43 b1:45 b2:44 b1:46 b2:45 b1:47 b2:46 b1:48 b2:47 b1:49 b2:48 b1:50
b2:49 b1:51 b2:50
b1:52 b2:51 b1:53 b2:52 b1:54 b2:53 b1:55 b2:54 b1:56 b2:55 b1:57 b2:56 b1:58 b2:57 b1:59 b2:58 b1:60
b2:59 b1:61 b2:60
b1:62 b2:61 b1:63 b2:62 b1:64 b2:63 b1:65 b2:64 b1:66 b2:65 b2:66 b1:67 b1:68 b2:67 b1:69 b2:68 b1:70
b1:71 b2:69 b1:72 b2:70
b1:73 b1:74 b2:71 b1:75 b2:72 b1:76 b1:77 b2:73 b1:78 b2:74 b1:79 b1:80
b2:75 b1:81 b2:76 b1:82 b1:83 b2:77 b1:84 b2:78 b1:85 b2:79 b1:86 b1:87 b1:88 b1:89 b1:90
b2:80
b1:91 b2:81 b1:92 b2:82 b1:93 b2:83 b1:94 b2:84 b1:95 b2:85 b1:96 b2:86 b1:97 b2:87 b1:98 b2:88 b1:99 b2:89 b1:100
b2:90
b2:91 b2:92 b2:93 b2:94 b2:95 b2:96 b2:97 b2:98 b2:99 b2:100