O'Reilly logo

Hands-On Enterprise Java Microservices with Eclipse MicroProfile by Scott Stark, Antoine Sabot-Durand, Pavol Loffay, Jeff Mesnil, Heiko W. Rupp, Cesar Saavedra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Timers

A timer basically is a combination of a histogram and a meter and can again be declared via an annotation:

@GET@Path("/hello")@Timed(name="helloTime", absolute = true,        description = "Timing of the Hello call",       tags={"type=timer","app=shop"})public String getHelloTimed() {  try {    Thread.sleep((long) (Math.random()*200.0));  } catch (InterruptedException e) {     // We don't care if the sleep is interrupted.  }  return "Hello World";}

The code in this example waits for a small random amount of time to make the output a bit more interesting.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required