Use a thread pool to optimize resource usage instead of always firing up new threads (less garbage collection).
Note: this is not a complete revert of r2153 since the pool is now automatically expanded as needed (different implementation).
This commit is contained in:
parent
71dbdf3417
commit
f6064ff19f
1 changed files with 12 additions and 8 deletions
|
@ -18,6 +18,8 @@ import java.util.concurrent.BlockingQueue;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
@ -140,6 +142,8 @@ public class MessagingController implements Runnable
|
|||
|
||||
ConcurrentHashMap<Account, Pusher> pushers = new ConcurrentHashMap<Account, Pusher>();
|
||||
|
||||
private final ExecutorService threadPool = Executors.newCachedThreadPool();
|
||||
|
||||
public enum SORT_TYPE
|
||||
{
|
||||
SORT_DATE(R.string.sort_earliest_first, R.string.sort_latest_first, false),
|
||||
|
@ -401,7 +405,7 @@ public class MessagingController implements Runnable
|
|||
*/
|
||||
public void listFolders(final Account account, final boolean refreshRemote, final MessagingListener listener)
|
||||
{
|
||||
new Thread(new Runnable()
|
||||
threadPool.execute(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
|
@ -457,7 +461,7 @@ public class MessagingController implements Runnable
|
|||
l.listFoldersFinished(account);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
}
|
||||
|
||||
private void doRefreshRemote(final Account account, MessagingListener listener)
|
||||
|
@ -557,13 +561,13 @@ public class MessagingController implements Runnable
|
|||
*/
|
||||
public void listLocalMessages(final Account account, final String folder, final MessagingListener listener)
|
||||
{
|
||||
new Thread(new Runnable()
|
||||
threadPool.execute(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
listLocalMessagesSynchronous(account, folder, listener);
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -699,7 +703,7 @@ public class MessagingController implements Runnable
|
|||
+ ")");
|
||||
}
|
||||
|
||||
new Thread(new Runnable()
|
||||
threadPool.execute(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
|
@ -891,7 +895,7 @@ public class MessagingController implements Runnable
|
|||
listener.searchStats(stats);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
}
|
||||
|
||||
public void loadMoreMessages(Account account, String folder, MessagingListener listener)
|
||||
|
@ -3101,7 +3105,7 @@ public class MessagingController implements Runnable
|
|||
{
|
||||
l.loadMessageForViewStarted(account, folder, uid);
|
||||
}
|
||||
new Thread(new Runnable()
|
||||
threadPool.execute(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
|
@ -3159,7 +3163,7 @@ public class MessagingController implements Runnable
|
|||
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue