Hi all
I am trying to get my head around threads, and after attempting many times to get my head around it, I am stuck on this point.
I want to get some remote data from a server. I create a thread to handle this operation. I understand this. But if I want to get some more remote data, I end up creating a new thread. This seems a bit daft, as shouldnt I be able to re-use the existing thread.
After trying to understand how I could do this, I think the answer lies in sending messages to the thread? But I am totally baffled by this.
Here is a example of where I need to get lots of remote data based on a variable within a for statement:
for(int i = 0; i < jsonarray.length(); i++){
String httpUserId = jsonarray.getJSONObject(i).getString("user_id");
//Get Sub Comments
userId = httpUserId
Thread t = new Thread(null, getUserPrefs, "getUserPrefs");
t.start();
}
As you can see in the example, I need to call the remote server lots of times, but instead of creating a new thread each time, shouldnt I be able to reuse one thread that I can create earlier?
If anyone can help I would be most grateful :)