Guidance on creating a server that has a group of threads to process requests
Say I am 1000 pop emails that I have to pull emails from.
I want to create a service, that utilizes muliple threads so I can pull email fro开发者_如何转开发m multiple pop3 servers at the same time (as oppose to a serialized process).
How would I go about doing this?
Use ThreadPoolExecutor.
Description of ThreadPoolExecutor from API doc:
public class ThreadPoolExecutor extends AbstractExecutorService
An ExecutorService that executes each submitted task using one of possibly several pooled threads, normally configured using Executors factory methods.
Thread pools address two different problems: they usually provide improved performance when executing large numbers of asynchronous tasks, due to reduced per-task invocation overhead, and they provide a means of bounding and managing the resources, including threads, consumed when executing a collection of tasks. Each ThreadPoolExecutor also maintains some basic statistics, such as the number of completed tasks.
Here is simple tutorial for understanding same.
Some more links to understand same:
http://programmingexamples.wikidot.com/threadpoolexecutor
Since you have a specific requirement for thrading a networked application, Apache Mina may be of interest.
From the homepage:
Apache MINA is a network application framework which helps users develop high performance and high scalability network applications easily. It provides an abstract · event-driven · asynchronous API over various transports such as TCP/IP and UDP/IP via Java NIO.
精彩评论