I have a Java application in which I have a socket. Now it is very important that only one socket is open at any point. I believe that a good way to ensure this is to create a wrapper class that will use the singleton property in the instance Socket. To clarify: by the singleton pattern, I mean the following generic class design:
public class Singleton {
private static final Singleton INSTANCE = new Singleton();
private Singleton(){ }
public static Singleton getInstance( ) {
return INSTANCE;
}
}
I am wondering if the concept of a singleton socket makes sense conceptually. SocketI will have to be able to reconnect and disconnect at any time throughout the program, and I'm not sure if this is possible using a single singlet.
As far as I can tell, this is not possible, although I hope there is some kind of trick or I just misunderstand something.