title: Threads and Observer Pattern
body: <p>I am trying to write Observe pattern in Java in multithread program to develop own logging program. My program is used in any Java class and can create the <code>Logger</code> class, and write a message to the logger. Logger class will call the logger manager class , which is a Singleton class and it also have the private class which is thread, on execution a scheduler runs, So I kept that execution in the private constructor.</p>
  
  <pre><code>private void LoggerManager() { 
      System.out.println("IN CONSTRUCTOR"); 
      executorThread.submit(new CreateLoggerFileForSpecifiedTime());
  }
  
  static LoggerManager getInstance() {
      if (LOGMANAGER == null) {
          synchronized (LoggerManager.class) {
              if(LOGMANAGER == null){
                  System.out.println("IN MANAGER");
                  LOGMANAGER = new LoggerManager();
              }
          }
      }
      return LOGMANAGER;
  }
  </code></pre>
  
  <p>Next there is a method in the LoogerManager "writeMessageToLog". </p>
  
  <pre><code>void writeMessageToLog(String componantName, String message, 
                       Calendar messageCreationTime) { 
      LoggerDetails logDetails = new LoggerDetails(componantName, message,
                       messageCreationTime); 
      LogInitiater logIntiater = new LogInitiater(logDetails, noticeOfLoggerChange, 
                       noticeOfMessageAdded); 
      executorThread.submit(logIntiater); 
  } 
  </code></pre>
  
  <p><code>LogIntitiater</code> is a thread which is added the LogWriter to two Subject's, One subject is a scheduler I have pasted above i.e a Timer runs for every specified time and notfiies <code>LogWriter</code> the need to create a new log file while the other purpose is when a message is added in the queue. Code is not working as expected:
  * scheduler code is not running, I tried with <code>execute</code> as well. That private constructor is not being called
  * thread initiater is not always called
  * observe pattern:  I have used J2SE interfaces i.e <code>Observable</code> and <code>Observe</code> and they are not working as expected</p>
  
  <p>Please help me.</p>