Become a fan of Slashdot on Facebook

 



Forgot your password?
typodupeerror
×
GNU is Not Unix

Journal cyranoVR's Journal: Java: A Verbose Acronym 9

Can you spot the error?

import some.imaginary.package.MyService;
 
public class MyServiceFactory {
 
    private static MyService instance;
 
    String factoryName;
 
    public MyServiceFactory(String factoryName) {
        this.factoryName = factoryName;
    }
 
    public Object getService() {
// create if null...
    synchronized(this) {
            if(MyServiceFactory.instance == null) {
            MyServiceFactory.instance = new MyService();
            }
    }
    return MyServiceFactory.instance;
    }
 
    public static void main(String args[]) {
        Thread a = new Thread() {
            public void run() {
                MyService service = new MyServiceFactory("a").getService();
        service.doStuff();
        }
    };
 
    Thread a = new Thread() {
            public void run() {
                MyService service = new MyServiceFactory("b").getService();
        service.doStuff();
            }
        };
 
    a.start();
    b.start();
    }
}

The error is not a syntax one, so if I'm missing a semi-colon or something, please assume that's unintentional.

This discussion was created by cyranoVR (518628) for Friends and Friends of Friends only, but now has been archived. No new comments can be posted.

Java: A Verbose Acronym

Comments Filter:

FORTRAN is a good example of a language which is easier to parse using ad hoc techniques. -- D. Gries [What's good about it? Ed.]

Working...