title: Java: Keep order using threads
body: <p>I have multiple threads that log some info throug my svc object.</p>
  
  <pre><code>public class SomeObject implements Runnable {
      @Override
      public void run() {
          ...
          svc.log("Reading file ...");
          .. some stuff...
          svc.log("Processing numbers ...");
          ... more stuff ...
          svc.log("Calculating power ...");
          ... and more stuff ...
      }
  }
  </code></pre>
  
  <p>The log processing was too expensive, so I decided to use another thread to do the log process.
  First I created a new thread per each log operation. It was faster but I ran out memory. So I decided to create a Singleton thread that just log the messages. It's faster and use less memory, but now I have a new problem: the log is being written in other order...
  Sometimes I have</p>
  
  <pre><code>Calculating power...
  Reading file...
  Processing numbers ...
  </code></pre>
  
  <p>instead of</p>
  
  <pre><code>Reading file...
  Processing numbers ...
  Calculating power...
  </code></pre>
  
  <p>I tried using <code>BlockingQueue</code>, so instead log directly, I put the messages in the queue and then just read and log the messages in it, but I have the same problem with the order.</p>
  
  <p>I have another idea: put the messages into a synchronized collection, specifying an order throug a variable and pop the elements depending on the variable, but it sounds weird.</p>
  
  <p>Any ideas to keep using of threads and keep order insertion?</p>