A
A
Andrey Kovalchuk2016-06-04 15:06:58
Java
Andrey Kovalchuk, 2016-06-04 15:06:58

How to properly organize a background thread on a Rest server?

Good day.
There is a system: Rest server, which performs two functions: it responds to requests from a mobile client and polls the microcontroller to record the data received from it.
If the program communicates with the client by executing his requests, then how to properly organize the process of working with the controller? We need a constant polling of the device with a specified interval (t).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2016-06-04
@mrkovalchuk

Option 1.
Periodically polling the controller (by cron or through sleep, if necessary more than once a minute) by a separate process, adding the results to the database, processing the results as needed.
The client receives the result from the database.
Option 2.
Polling the controller at the time of the client's request, caching the polling result for N seconds (in memory, on disk, in the database).
It all depends on the required polling frequency, the time of one poll, and so on.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question