开发者

Multithreaded Server Client in MyBatis

开发者 https://www.devze.com 2023-03-25 06:20 出处:网络
I have coded a single threaded client server model which does following: Server loops for clientwaiting..

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 myb开发者_如何学Goatis 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消