http://www.blogjava.net/sterning/archive/2007/10/15/152940.html
多线程Java Socket编程示例
这篇做为学习孙卫琴<<Java网络编程精解>>的学习笔记吧.其中采用Java 5的ExecutorService来进行线程池的方式实现多线程,模拟客户端多用户向同一服务器端发送请求.
1.服务端
![](http://cjb.iteye.com/Images/OutliningIndicators/None.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/None.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/None.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/None.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/None.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/None.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/None.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/None.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/None.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/None.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/None.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/None.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
2.客户端
![](http://cjb.iteye.com/Images/OutliningIndicators/None.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/None.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/None.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/None.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/None.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/None.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/None.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/None.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/None.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/None.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/InBlock.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](http://cjb.iteye.com/Images/OutliningIndicators/None.gif)
从而实现了多个客户端向服务器端发送请求,服务器端采用多线程的方式来处理的情况.再结合我之前的例子---Java基于Socket文件传输示例,就可以实现多线程文件的传输了