jeudi 12 novembre 2015

Are there big differences in way of geting singelton instances?

Hello I would like to know how to properly get singleton instances and what is best practice?

public class SingeltonTest {

private static final CounterSingelton COUNTER = CounterSingelton.getInstance();

public static void main(String[] args) {

    //Type A
    for (int a = 0; a < 100; a++) {
        COUNTER.increase();
    }

    //Type B
    for (int a = 0; a < 100; a++) {
        CounterSingelton counter = CounterSingelton.getInstance();
        counter.increase();
    }

    //Type C
    for (int a = 0; a < 100; a++) {
        CounterSingelton.getInstance().increase();
    }
}

}

Aucun commentaire:

Enregistrer un commentaire