Synchronizace: Porovnání verzí
Smazaný obsah Přidaný obsah
Bez shrnutí editace značka: editace z Vizuálního editoru |
Bez shrnutí editace značka: editace z Vizuálního editoru |
||
Řádek 14:
== Příklady synchronizace ==
'''synchronizace metody:'''
public synchronized void iterate(){
if(this.i < endValue){
System.out.println(Thread.currentThread().getName() + ": " + this.i++);
}
}
'''synchronizace bloku:'''▼
public void iterate(){
synchronized(this){
if(this.i < endValue){
System.out.println(Thread.currentThread().getName() + ": " + this.i++);
}
}
}
'''statická synchronizace:'''▼
public static void iterate(){
synchronized(Counter3.class){
if(i < endValue){
System.out.println(Thread.currentThread().getName() + ": " + i++);
}
}
}
public static synchronized void iterate2(){
if(i < endValue){
System.out.println(Thread.currentThread().getName() + ": " + i++);
▲synchronizace bloku:
}
}
▲statická synchronizace:
== Související články ==
|