I have 2 classes. One (A) collects some data, and the other (B) sends data to TCP / IP clients. The process is asynchronous with an update rate of almost zero to several seconds. Please note that this application does not have a graphical interface, so I will not be able to use many of the built-in listeners in "onChange".
Under normal circumstances, I’ll just write the code so that A calls the “send” method to B, passing the data, no problem here.
Now suppose that the data collection rate of A is critical (in real time) and that A cannot wait for B to complete the sending process (note that B uses TCP, not UDP). The way I implemented this is
- A puts data in a field in B
- B has a continuous loop that checks if the data is new or now. If new, he will send it.
If the data is updated several times during sending, it does not matter if it does not slow down A. Creating a new thread for each send would not slow down A in principle, but it will probably lead to a mess.
You can see that B runs in synchronous mode (but A does not), and it is implemented with a while loop with a call to Thread.sleep (). My questions:
* : , A , B . , B *
? , .
!