hi!
weiss jemand, warum printme() nicht wirklich exclusiv ausgeführt wird?
Ausgabe ist bei mir:
irgendwie hab ich gehofft, dass mehr so etwas herauskommt:
ist bestimmt was ganz einfaches und logisches, oder?
gruß
micha
weiss jemand, warum printme() nicht wirklich exclusiv ausgeführt wird?
Code:
public class test extends Thread {
int a=5;
public test(int a){
this.a=a;
}
public synchronized void printme(){
try{double i=0;
while(i<3){
i++;
System.out.println(i);
}
System.out.println("inside printme()");
System.out.println(a+"+"+a);}
catch(Exception e){}
}
public void run(){
printme();
}
public static void main(String[] args) {
test t1=new test(1);
test t2=new test(2);
test t3=new test(3);
t1.start();
t2.start();
t3.start();
System.out.println("prog ende");
}
}
Code:
1.0
2.0
3.0
1.0
2.0
3.0
inside printme()
2+2
inside printme()
1+1
1.0
prog ende
2.0
3.0
inside printme()
3+3
Code:
1.0
2.0
3.0
inside printme()
1+1
1.0
2.0
3.0
inside printme()
2+2
1.0
2.0
3.0
inside printme()
3+3
ist bestimmt was ganz einfaches und logisches, oder?
gruß
micha