English, asked by shaikhab63, 1 year ago

1) if a client requests timestamping every two minutes, how would it look?

Answers

Answered by Anonymous
0
Original Question: If a client requests timestamping every two minutes, how would it look like?

My Answer: You haven’t specifically defined what “timestamping” involves or what exactly you’re looking for, but I’ll assume that it’s any sort of “ping” to a server or log file that contains the timestamp of the message and some additional data.

Additionally, you do not specify whether it’s every 2 minutes clock-time (12:00, 12:02, 12:04) or exactly 2 minutes after the last timestamping operation completes (12:00:30, 12:02:32, 12:04:32, etc.).

The best approach would be to use your Operating System’s or platform’s built-in scheduler or any sort of TaskManager: on iOS, that would be the `NSTimer` class; on *Nix systems, that would be `chron`, both of which would allow you to specify the operation to take place and the frequency at which the operation should execute.

For example, you can have `chron` run a bash script or any other script (i.e.: a Python program) every 2 minutes, and that script could do the timestamping you want: sending a request to the server or writing to a file.

That approach is usually the best as it allows the OS to handle executing your code, which means it can instantiate and destroy threads when needed thereby reducing background resource consumption.

The next best approach would be to instantiate a separate background thread, have it run in an infinite loop to ensure it’s always running, and have it sleep for 2 minutes before executing your timestamping logic. In Java, this would involve using the `Thread` class and the `Thread.sleep()` method.

This approach isn’t as ideal as you will always need to have a thread running in the background, but at least it won’t use up the CPU during the 2 minutes in between timestamping. Additionally, if your timestamping logic takes a semi-random amount of time to execute (i.e.: sometimes it takes 4 seconds, othertimes it takes 10 seconds), you will need to modify the amount of time that the Thread sleeps so that it does not oversleep and run at different times.

The last approach would be like the prior one, but rather than using Thread.sleep(), you constantly check the time in your infinite-loop to see if 2 minutes have elapsed and if it’s time to execute the timestamping logic.

This is more CPU intensive as the CPU must keep on executing your timecheck comparison statements, and depending on your implementation, there is a chance your code might not run even though it should (i.e.: if you program it to run every 2 minutes when the nanoseconds are exactly .000000, but by the time the comparison executes the nanoseconds are .000234, your code might not run.

PLAESE MARK AS BRAINLIEST
Similar questions