java线程
class Thread1 implements Runnable{
int sum1=0;
private int a=1;
public void run(){
while(true){
try{
Thread.sleep(10);
}catch(InterruptedException e){
e.printStackTrace();
}
if(a==11){
break;
}
else{
sum1=sum1+a;
a++;
}
synchronized(Example4.class){
Example4.class.notifyAll();
}
}
Thread t1=Thread.currentThread();
String t1_name=t1.getName();
System.out.println(t1_name+sum1);
}
}
class Thread2 implements Runnable{
int sum2=0;
private int a=10;
public void run(){
while(true){
try{
Thread.sleep(10);
}catch(InterruptedException e){
e.printStackTrace();
}
if(a==21){
break;
}
else{
sum2=sum2+a;
a++;
}
synchronized(Example4.class){
Example4.class.notifyAll();
}
}
Thread t2=Thread.currentThread();
String t2_name=t2.getName();
System.out.println(t2_name+sum2);
}
}
class Thread3 implements Runnable{
int sum3=0;
private int a=20;
public void run(){
while(true){
try{
Thread.sleep(10);
}catch(InterruptedException e){
e.printStackTrace();
}
if(a==31){
break;
}
else{
sum3=sum3+a;
a++;
}
synchronized(Example4.class){
Example4.class.notifyAll();
}
}
Thread t3=Thread.currentThread();
String t3_name=t3.getName();
System.out.println(t3_name+sum3);
}
}
public class Example4 {
public static void main(String[] args) {
Thread1 t1=new Thread1();
Thread2 t2=new Thread2();
Thread3 t3=new Thread3()
new Thread(t1,"线程一结果:").start();
new Thread(t2,"线程二结果:").start();
new Thread(t3,"线程三结果:").start();
}
}
这段程序怎么输出SUM1+SUM2+SUM3?