How can I guarantee that the "wait" is sent?

We have an RMI client application written in Java that should send periodic β€œleft” messages to the server application. We implemented this as a separate heartbeat stream that sends a live message to the server and then sleeps for 15 seconds using Thread.sleep ().

The stream is set to high priority:

Thread heartbeatThread = new Thread(new HeartbeatRunnable(server));
heartbeatThread.setPriority(Thread.MAX_PRIORITY);
heartbeatThread.start();

However, when the box on which the client is running uses a lot of CPUs, we find that the heartbeats are missing, which makes the server assume that our client application is dead.

We added Thread.yield () calls in my main thread, although this did not fix the problem.

Is there a way to ensure that the heartbeat is sent on time while my application is still running?

+3
source share
6 answers

You can embed user-mode threads in a non-threaded environment by dividing the self-written exit function in your code.

Similarly, you can freely scatter calls to the heart rate check functions in your code. Change the flow, just regularly call the heartbeat function, which checks if you still need to send a pulse.

This is a tough decision, but given that you have tried the right solution and it doesn’t work, maybe this is what you should return to.

In fact, what you could do is put a macro at the beginning of each function call, which makes a quick time check and, if necessary, calls the heartbeat function.

(, Java? , , ).

+1

. , , , . , , , , .. 15 () 7,5 .

+3

, .

, , , , heartbeart. , : " ", , , .

heartbeat , , " , , ", , , . - , .

+2

" ", , , .

, , 15 , 4, 60 (1 ), , .

+1

, Timer scheduleAtFixedRate. , ( Java), .

0

, , , . . ( ), /, IOException, , / .

This will not depend on the server providing a timely heartbeat. It uses several resources (TCP port on the server side and near the lack of bandwidth), and timely detect when the server (or server machine) becomes unavailable.

0
source

Source: https://habr.com/ru/post/1705248/


All Articles