多线程 - Java中如何安全地进行线程间通信?
PHP中文网
PHP中文网 2017-04-17 17:47:10
0
2
382

业务是这样的:
有一个硬件设备, 会不停地向服务器通过socket上传数据, 同时, 这个数据需要实时地传递给APP端用作显示.

socket服务器监听到一个新的socket时, 会新建一个socket进行处理.

但是现在不知道怎么把数据给app了.

请大家给给建议. 谢谢.

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
黄舟
  1. The hardware device uploads the collected data to a cache server

  2. Establish an Application Server to handle app requests and get data from the current cache server

  3. The client app accesses the application server
    In general, it is asynchronous and there is no inter-thread communication. In addition, only when each thread is independent of each other can it be truly parallel

If inter-thread communication (waiting for notify) is required, it is basically equivalent to serial.
Determine the implementation of cache server and application server based on the amount of data collected and whether the collected historical data needs to be saved.
Please add some questions first. . .

巴扎黑

That’s not communication between threads, but communication between different processes, and it should be across machines.
You can:

  1. The app establishes a long connection with the server, and then the server pushes the data to the app

  2. The app regularly queries the server for data
    There are many other methods. It depends on your environment and business needs to choose the most suitable method.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template