title: Singleton with initializing a static member
body: <p>In the code snippet below when I originally designed it, the "next number" needed to send the next incremented value throughout the execution of the application. So I made the class a singleton. However, with some recent change in requirements I needed to do a reset on the "next number". I just added a reset method to do that. However, it definitely violates the Singleton pattern and also I know it is not a good idea to initialize a static member this way. </p>
  
  <p>What do you think I should do instead? </p>
  
  <pre><code>public final class GetNextNumber {
      private static GetNextNumber instance; 
      private static Integer nextNumber=1;
      private GetNextNumber() {
      }
      public static synchronized GetNextNumber getInstance() {
          if(instance==null){
              instance = new GetNextNumber();
          }
          return instance;
      } 
      protected Integer getNextNumber(){
          return nextNumber++;
      }
      protected synchronized void reset(){
          nextNumber=1;
      }
      public Object clone() throws CloneNotSupportedException {
          throw new CloneNotSupportedException();
      }
  }
  </code></pre>