package com.credera.vinnylapenna;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/wait")
public class WaitController {

  Object lock = new Object();

  @GetMapping()
  public long waitOnLockFiveSeconds() throws InterruptedException {
    return this.waitOnLock(5000);
  }

  @GetMapping("/{millis}")
  public long waitOnLock(@PathVariable long millis) throws InterruptedException {
    long start = System.currentTimeMillis();
    long end;

    synchronized(lock) {
      Thread.sleep(millis);
      end = System.currentTimeMillis();
    }

    // Note that this time will not necessarily reflect the actual time the browser waits to receive a response
    return end - start;
  }

}

@@ -351,39 +351,8 @@
  %7B%0A%0A
-  Object lock = new Object();%0A%0A
   @G
@@ -364,34 +364,36 @@
 ping()%0A  public 
-lo
+Stri
 ng waitOnLockFiv
@@ -508,18 +508,20 @@
  public 
-lo
+Stri
 ng waitO
@@ -632,66 +632,35 @@
 ();%0A
+%0A
     
-long end;%0A%0A    synchronized(lock) %7B%0A      Thread.sleep
+doSomethingInteresting
 (mil
@@ -665,21 +665,25 @@
 illis);%0A
+%0A
     
- 
+long
  end = S
@@ -712,14 +712,8 @@
 s();
-%0A    %7D
 %0A%0A  
@@ -837,19 +837,198 @@
 urn 
-end - start
+%22doSomethingInteresting() took %22 + (end - start) + %22 milliseconds%22;%0A  %7D%0A%0A  private synchronized void doSomethingInteresting(long millis) throws InterruptedException%7B%0A    Thread.sleep(millis)
 ;%0A  

Refactor WaitController