title: Making Class thread safe
body: <p>This code is generated for saving event history in my app as I need to provide some code as :</p>
  
  <pre><code>public class LogDataBase {
      public LogDataBase(Context context) {
          try {
              this.context = context;
              String logPath = context.getFilesDir() + logStoragePath;
              file = new File(logPath);
              if (!file.exists()) {
                  file.createNewFile();
              }
          } catch (Exception e) {
          Errors += ("\n" + e.getMessage());
          }
      } 
      public void addItem(String log) {
          try {
              dbWriter = new FileWriter(file, true);
              //appand String log to file
              ....
      }
     public ArrayList&lt;String&gt; getArrayList() { 
       //get all Logs as arraylist
      }
  }   
  </code></pre>
  
  <p>The main question is how to develop app that is thread-safe? As apps may use services and multiprocessing ,multi-threading should ensure that codes and classes is safe.</p>
  
  <p>Please provide some Comprehensive explanation for this important topic(not only saying <code>Synchronization , Lock,...</code>) <br/>
  hope to be useful for others<br/>
  Thanks in advance.</p>