不可思议的结果。。。谁能帮忙解释下。。。
运行结果:
线程1开始:帮忙 a 长江 长江 bag 东方 country 黄河
线程2开始:黄河 country 黄河 country 可能 hello
线程3开始: 可能 hello 你好 is this 我 this where 阳光
线程4开始:阳光 where women 字典 字典 women
线程1结束:str_PartText[0]=帮忙 a 长江 bag 东方 country 黄河
线程2结束:str_PartText[1]=黄河 country 可能 hello
线程3结束:str_PartText[2]= 可能 hello 你好 is this 我 where 阳光
线程4结束:str_PartText[3]=阳光 where women 字典
线程结束
false
false
false
false
int_temp is :4
线程1开始:帮忙 a 长江 bag 东方 country 黄河 黄河 country 可能 hello
线程2开始: 可能 hello 你好 is this 我 where 阳光 阳光 where women 字典
线程2结束:str_PartText[1]= 可能 hello 你好 is this 我 where 阳光 women 字典
线程1结束:str_PartText[0]=帮忙 a 长江 bag 东方 country 黄河 可能 hello
线程结束
false
false
int_temp is :2
线程1开始:帮忙 a 长江 bag 东方 country 黄河 可能 hello 帮忙 a 长江 bag 东方 country 黄河 可能 hello
线程1结束:str_PartText[0]=帮忙 a 长江 bag 东方 country 黄河 可能 hello
线程结束
false
int_temp is :1
排序结果为:
-------------------------
帮忙 a 长江 bag 东方 country 黄河 可能
hello
run方法为:
public void run(){
if(Thread.currentThread()==thr_StringSort[0]){
String string_guibing=str_PartText[0]+str_PartText[1];
System.out.println("线程1开始:"+string_guibing);
try{
Thread.sleep(10);
}catch(InterruptedException e){
e.printStackTrace();
}
string_guibing=PaiChong(string_guibing);
str_PartText[0]=Sort(string_guibing);
System.out.println("线程1结束:str_PartText[0]="+str_PartText[0]);
}
if(Thread.currentThread()==thr_StringSort[1]){
String string_guibing=str_PartText[2]+str_PartText[3];
System.out.println("线程2开始:"+string_guibing);
try{
Thread.sleep(10);
}catch(InterruptedException e){
e.printStackTrace();
}
string_guibing=PaiChong(string_guibing);
str_PartText[1]=Sort(string_guibing);
System.out.println("线程2结束:str_PartText[1]="+str_PartText[1]);
}
if(Thread.currentThread()==thr_StringSort[2]){
String string_guibing=str_PartText[4]+str_PartText[5];
System.out.println("线程3开始:"+string_guibing);
try{
Thread.sleep(10);
}catch(InterruptedException e){
e.printStackTrace();
}
string_guibing=PaiChong(string_guibing);
str_PartText[2]=Sort(string_guibing);
System.out.println("线程3结束:str_PartText[2]="+str_PartText[2]);
}
if(Thread.currentThread()==thr_StringSort[3]){
String string_guibing=str_PartText[6]+str_PartText[7];
System.out.println("线程4开始:"+string_guibing);
try{
Thread.sleep(10);
}catch(InterruptedException e){
e.printStackTrace();
}
string_guibing=PaiChong(string_guibing);
str_PartText[3]=Sort(string_guibing);
System.out.println("线程4结束:str_PartText[3]="+str_PartText[3]);
}
if(Thread.currentThread()==thr_StringSort[4]){
String string_guibing=str_PartText[8]+str_PartText[9];
string_guibing=PaiChong(string_guibing);
str_PartText[4]=Sort(string_guibing);
}
}