I have a thread which pushes data into a queue and another thread which reads data from queue and processes it. I would like to check how long the data sits in the queue before getting processed.
I added a time parameter (calculated using System.nanoTime()
) in the data before being pushed by the first thread. Once the second thread processes it, it will calculate System.nanoTime()
and find the difference from the previous time set in the data.
Would this work properly? I am asking this because I am seeing negative difference in the logs.
UPDATE
I would like to clarify that, the start time is put by a process in a different machine and the difference is calculated in a different machine.