What are the risks in using Singleton in java

Asked

Viewed 25 times

0

Hello, What are the risks of error when using the Singleton practice in java? I am using the following:

private Os mInstance = null;
private int numeroOs, updateServer;
Context context;

    public synchronized Os getInstance(Context c,  int numeroOs) {
        context = c;
        if (mInstance == null) {
            mInstance = new Os(context.getApplicationContext(), numeroOs);
        }

        return mInstance;
    }

    protected Os(Context context, int numeroOs) {
        this.numeroOs = numeroOs;
        this.context = context;
    }

When should I instantiate the class Os (for example) to set the input parameters "context and numeroOs"? and if it is not instantiated what happens?

  • 3

    Risk? Wrong modeling is a high risk

  • 5

    I guess just the fact that you’re wearing it and not knowing the risk is a big enough risk.

  • This case of yours wouldn’t be a multiton?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.