title: Multithreaded code in AsyncTask doInBackground
body: <p>Can there be a performance benefit to running multithreaded code in the doInBackground() function of the android AsyncTask class? This is a rough sketch of my plan:</p>
  
  <pre><code>private class MyBackgroundTask extends AsyncTask&lt;Integer, Integer, Integer&gt;
  {
      protected Integer doInBackground(Integer... vals)
      {
          Thread[] thrds = new Thread[NUM_THREADS];
          //Start all threads
          for(int i = 0; i &lt; thrds.length; ++i)
          {
              thrds[i] = //Initialize threads
              thrds[i].start();
          }
          //Wait for all threads to finish
          for(int i = 0; i &lt; thrds.length; ++i)
              thrds[i].join();
          //Post processing...
          return foo;
      }
  
      protected void onPostExecute(Integer res)
      {
          //Pass value back to UI class
      }
  }
  </code></pre>
  
  <p>Will this spawn new threads which can be taken advantage of on a multi-core device? For instance, if the threads were each searching a (very-large) array for a maximum value, would there be a performance speed up on a multi-core device? Or will this result in something like "many-to-one" behavior. </p>
  
  <p>One more thing, I want to multi-thread using Threads instead of calling multiple AsyncTasks, because the multi-threading will ultimately be handling domain level processing. I would strongly prefer to decouple the domain level processing from the UI classes so I can reuse the domain level classes with a different UI.</p>
  
  <p>Thanks in advance.</p>