*> Synchronize on an object's monitor,
*> in this case the current object
class-id synchronization public.
01 _items list[string].
method-id addItemsSafe (items as string occurs any).
sync on self
perform varying auto item thru items
write _items from item
end perform
end-sync
end method.
method-id addItemSafe (item as string) sync.
write _items from item
end method.
end class.
|
Class
// Synchronize on an object's monitor
// in this case the current object
public class synchronization {
private ArrayList<string> _items;
public void addItemsSafe(String[] items) {
synchronized (this) {
for (String item : items) {
_items.add(item);
}
}
}
synchronized public void addItemSafe(String item) {
_items.add(item);
}
}
|