同期 (COBOL、Java)

COBOL Java
*> 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);
    }
}

これらの例の一部は、ハーディング大学コンピューター サイエンス学部の Frank McCown 博士が作成したもので、クリエイティブ コモンズ ライセンスに基づいて使用が許可されています。