Multithreaded Server Client in MyBatis

点点圈 提交于 2019-12-11 11:33:29

问题


I have coded a single threaded client server model which does following:

  1. Server loops for client waiting..
  2. When client runs, it sends current data available (i.e. a string which has 10 fields seperated by comma)
  3. Server reads the data from client and decodes it (simply by checking for comma)
  4. 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.


回答1:


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




回答2:


As suggested by Gille, you can write a class that extends the Class Thread. This thread, started by the Server class, is listening for connections, available on the port you setted.

For example, a thread is listening for connection on port 7000, another thread on port 7500, and so on.

Obviously you have to import the Socket package in the Thread class, to send/receive data between client and server. Read this page for further information about the Socket package.

This is the page API for Thread Class for JavaSE 6.

Tutorial O'Reilly for threads here.



来源:https://stackoverflow.com/questions/6952490/multithreaded-server-client-in-mybatis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!