MyBatis中的多线程服务器客户端
问题描述:
我编写了一个单线程客户端服务器模型,它执行以下操作:
I have coded a single threaded client server model which does following:
- 服务器循环客户端等待..
- 当客户端运行时,它发送当前可用的数据(即一个由逗号分隔的10个字段的字符串)
- 服务器从客户端读取数据并对其解码检查逗号)
- 然后使用mybatis服务器更新数据库。
- Server loops for client waiting..
- When client runs, it sends current data available (i.e. a string which has 10 fields seperated by comma)
- Server reads the data from client and decodes it (simply by checking for comma)
- Then using mybatis server updates database.
这个服务器到多线程的一个,我真的很困惑,看看我在谷歌搜索(即聊天服务器等)发现的一些例子。
Now I want to convert this server to multithreaded one and I am really confused looking at some examples that I found while googling (i.e. chat server etc.).
所以,任何人都可以帮助我
So, can anyone please help me out where exactly to start from to convert server into a multithreaded one?
如果需要,我可以将代码放在这里。
I can post the code here if required.
答
您可以为每个传入连接启动一个线程。
在此页面的底部,您可以找到一个包含源代码的示例:写入套接字的服务器端
You could start a thread for every incoming connection. At the bottom of this page you can find an example with source code: Writing the Server Side of a Socket