title: java Multithreading (newCachedThreadPool ), then writing result to one file?
body: <p>I have tried to do this with simple Threads and succeded but I believe that using Threadpool I could do the same thing more effeciently:)?
  simple threads:</p>
  
  <pre><code>public static class getLogFile implements Runnable {
      private String file;
  
      public void setFilename(String namefile){
      file=namefile;
      }
      public int run1(String Filenamet) {
  
      connectToServer(XXX, Filenamet, XXX, XXX, XXX, XXX);//creates a file and downloads it
  
          return 0;
      }
  
      public void run() {
              run1(file);
      }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>in main:
  for(x=0 ; x &lt; 36 ; x++){
      String Filename1=Filename+x;
      getLogFile n=new getLogFile();
      n.setFilename(Filename1);
      (new Thread(n)).start();
  </code></pre>
  
  <p>}</p>
  
  <p>Program connects to the server executes 36 commands(using threadpool/simplethreads?!) at the same time and either downloads 36 result files, than merges them, or maybe it could just write to one file on server and then download it?</p>
  
  <ol>
  <li>how to transform this code into threadpools?</li>
  <li>how to write data to one file from 36 threads?</li>
  </ol>