![]() |
![]() |
|
|
|||||||
| Programmierung Rat & Tat für Programmierer |
|
|
Themen-Optionen | Ansicht |
|
|
#2 |
|
Inventar
![]() Registriert seit: 13.06.2001
Beiträge: 1.830
|
Wie du schon gesagt hast funktioniert synchronized nur auf Objekte, nicht auf primitive Typen (int, float, boolean, ...).
Das hier: Code:
public synchronized void run(){
Du synchronisierst run(), eigentlich willst du aber der inkrement/dekrement synchronisieren. Das würde in etwa so funktionieren: Code:
public class Global{
private static int number=1;
public synchronized void increment(){
number++;
}
public synchronized void decrement(){
number--;
}
}
____________________________________
Join the DNRC | Godwin\'s Law (thx@stona) Documentation is like sex: If it\'s good, it\'s very, very good. If it\'s bad, it\'s better than nothing. \"In theory, theory and practice are the same. In practice, they are not\" (Lawrence Berra) |
|
|
|
| Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1) | |
|
|