简体   繁体   English

MyBatis中的多线程服务器客户端

[英]Multithreaded Server Client in MyBatis

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 (ie a string which has 10 fields seperated by comma) 当客户端运行时,它将发送可用的当前数据(即,一个字符串,其中包含以逗号分隔的10个字段)
  3. Server reads the data from client and decodes it (simply by checking for comma) 服务器从客户端读取数据并对其进行解码(只需检查逗号即可)
  4. Then using mybatis server updates database. 然后使用mybatis服务器更新数据库。

Now I want to convert this server to multithreaded one and I am really confused looking at some examples that I found while googling (ie 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. 正如Gille所建议的,您可以编写一个扩展Class Thread的类。 This thread, started by the Server class, is listening for connections, available on the port you setted. 由Server类启动的此线程正在侦听您设置的端口上可用的连接。

For example, a thread is listening for connection on port 7000, another thread on port 7500, and so on. 例如,一个线程正在侦听端口7000上的连接,另一个线程正在侦听端口7500上的连接,依此类推。

Obviously you have to import the Socket package in the Thread class, to send/receive data between client and server. 显然,您必须在Thread类中导入Socket包,才能在客户端和服务器之间发送/接收数据。 Read this page for further information about the Socket package. 阅读此页面以获取有关Socket软件包的更多信息。

This is the page API for Thread Class for JavaSE 6. 这是JavaSE 6的线程类的页面 API。

Tutorial O'Reilly for threads here . 教程O'Reilly在这里提供线程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM