為什麼要起那麼多線程 ? 能不能開一個線程,再一個個的依序處理相關 json ?像… Runnable work = new Runnable() { @Override run() { int size = list.size(); for(int i =0 ; i < size; i++) { // post data to server } } };Thread thread = new Thread(work).start();然後其實可以用線程池(ThreadPool),如果你 post data 優先級不是那麼高的話~ 有錯請指正 :D
试试用线程池吧 或者 libcurl吧
你用AsyncTask挺好的,,相当于一个线程池了。 public final AsyncTask<Params, Progress, Result> executeOnExecutor (Executor exec, Params... params)Added in API level 11 Executes the task with the specified parameters. The task returns itself (this) so that the caller can keep a reference to it.This method is typically used with THREAD_POOL_EXECUTOR to allow multiple tasks to run in parallel on a pool of threads managed by AsyncTask, however you can also use your own Executor for custom behavior.
Runnable work = new Runnable() {
@Override
run() {
int size = list.size();
for(int i =0 ; i < size; i++) {
// post data to server
}
}
};Thread thread = new Thread(work).start();然後其實可以用線程池(ThreadPool),如果你 post data 優先級不是那麼高的話~
有錯請指正 :D
public final AsyncTask<Params, Progress, Result> executeOnExecutor (Executor exec, Params... params)Added in API level 11
Executes the task with the specified parameters. The task returns itself (this) so that the caller can keep a reference to it.This method is typically used with THREAD_POOL_EXECUTOR to allow multiple tasks to run in parallel on a pool of threads managed by AsyncTask, however you can also use your own Executor for custom behavior.