title: Android Keep thread alive questions
body: <p>I am building an Android App that will communicate over TCP with a server. I have a few ideas for implementation and I don't know which way would be best to go. I am new at this and my design is constantly evolving as I learn new things, so now I am looking for advice for how to best implement a solution to fulfill my goal.</p>
  
  <p>Goal: Be able to:</p>
  
  <ol>
  <li>send data to a server</li>
  <li><p>Send data to a server and read the servers response.</p>
  
  <ul>
  <li>Some information I send will be to give the server information, other will be to request information from the server.</li>
  </ul></li>
  </ol>
  
  <p>Possible implementations:</p>
  
  <ul>
  <li>Thread Run() method constantly loops through checking if my send queue has something to send (and sending it if it does) then checking if I have anything to read back in.
  <ul>
  <li>Will this drain battery/burn CPU?</li>
  </ul></li>
  <li>Create a new thread each time I want to send/receive, the let it die once I have done 'send' or 'send + receive'
  <ul>
  <li>How should I synchronize the threads interactions with my one socket? Block making the next thread until this one finishes?</li>
  </ul></li>
  <li>Make a thread and call a send or send + receive method withing that thread each time I need to write or write + read
  <ul>
  <li>How do I keep the thread alive without burning battery/CPU?</li>
  <li>should I use a queue to handle requests for transmitting data and should I synchronize reading from it until the current read/write is finished?</li>
  </ul></li>
  </ul>
  
  <p>Any additional pointers, links, or warnings about potential issues would be much appreciated. Sample code is especially appreciate as I am just starting out with this. Thank you.</p>