previous |
start |
next
Object Locks
- Each object has a lock
- Thread can lock, unlock object
- No other thread can lock object until unlocked
- Use synchronized
method
- Calling synchronized method locks implicit parameter
- No other thread can call another synchronized method on same
object
- Place thread-sensitive code inside synchronized methods
public synchronized void add(Object anObject)
{ ... }
previous |
start |
next