Class Design : Threading inside class or outside
<p>I have a class <code>Session</code> which tracks a bunch of counters and gets persisted to a database. My question is mostly a class design question, and not specific to Android but I'm working on Android, which is only relevant because I want to ensure writing to the database does not happen on <em>the</em> main thread. </p>

<p>I'm considering two alternatives for the <code>persist()</code> method which writes the session to a db (which could be potentially slow and I'm not overly concerned about whether/when it succeeds):</p>

<p><strong>Concurrency &amp; Execution inside</strong></p>

<pre><code>public class Session()
{
   //.. getters and setters...

   void persist()
   {
       Runnable r = new Runnable(){
          // Implement logic in run() with slow 
          // db operations
       };
       ExecutorService executor = getExistingExecutor();
       executor.submit(r);
   }
 }
</code></pre>

<p><strong>Concurrency &amp; Execution outside</strong></p>

<pre><code>public class Session()
{
   //.. getters and setters...

   void persist()
   {
     // Implement logic in run() with slow 
     // db operations
   }
 }
</code></pre>

<p>I'm basically wondering from an object design standpoint, what is the best way to wrap up neatly code that could be slow running so that its easy to use? I'm also interested if there is a division of labor issue (The <code>Session</code> store values for the session but also knows how to persist itself ... i can't decide if thats nice OO or overly complex).</p>
