It would be a good idea to use System.nanoTime() instead, which is the 
clock designed for measure how long something took.  
 System.currentTimeMillis() is meant for telling the current time, which is 
allowed to drift. 

On Tuesday, January 9, 2018 at 7:16:36 PM UTC-8, Joe Qiao wrote:
>
> Hi,
>
> I want to implement a server interceptor to collect how much time used in 
> server side from message received to process complete. 
> so i write a server interceptor which return a 
> SimpleForwardingServerCallListener which have a long field. then i record 
> the start time in the onMessage method, set it to the long field and 
> calculate the total time used in onComplete by using this field value.
> it's basically like this:
>
> return new SimpleForwardingServerCallListener(...){
>       private long start;
>
>      public void onMesage(...){
>        start = System.currentTimeMillis();
>        .....
>     }
>
>
>     public void onComplete(...){
>        log.info("time used:", System.currentTimeMillis() - start);
>        .....
>    }
>
> }
>
> is this implementation correct? is there any thread-safe issue here? 
> Thanks!
>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/52d25179-0555-4406-8c79-acb499874e51%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to