// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class WithSingleton {
    public void doSomething() {
        System.out.println(FoobarSingleton.getInstance().getV());
    }
    public static void main(String[] args) {
        FoobarSingleton.getInstance().setV(123);
        WithSingleton o = new WithSingleton();
        o.doSomething();
    }
}

class FoobarSingleton {
    private static FoobarSingleton instance = null;
    private FoobarSingleton() {
    }
    public static synchronized FoobarSingleton getInstance() {
        if(instance == null) {
            instance = new FoobarSingleton();
        }
        return instance;
    }
    private int v;
    public void setV(int v) {
        this.v = v;
    }
    public int getV() {
        return v;
    }
}
