package com.bsw.thread;
import java.io.*;
import java.lang.*;class ThreadTest implements Runnable{
public synchronized void run(){
for(int i=0;i<100;i++){
System.out.print(" "+i);
}
}
}public class Test {
public static void main(String[] args) {
Runnable r1 = new ThreadTest();
Runnable r2 = new ThreadTest();
Thread t1 = new Thread(r1);
Thread t2 = new Thread(r2);
t1.start();
t2.start();
}
}请高手帮小弟看看,我看教程说是输出结果应该是不确定的,但是为什么我试过之后是 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 。我也觉得不应该,大家帮忙看看
import java.io.*;
import java.lang.*;class ThreadTest implements Runnable{
public synchronized void run(){
for(int i=0;i<100;i++){
System.out.print(" "+i);
}
}
}public class Test {
public static void main(String[] args) {
Runnable r1 = new ThreadTest();
Runnable r2 = new ThreadTest();
Thread t1 = new Thread(r1);
Thread t2 = new Thread(r2);
t1.start();
t2.start();
}
}请高手帮小弟看看,我看教程说是输出结果应该是不确定的,但是为什么我试过之后是 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 。我也觉得不应该,大家帮忙看看
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货