@@ -113,29 +113,28 @@ public void handleTimeout(AsyncResponse asyncResponse) {
113113 asyncResponse .resume (Response .status (Response .Status .SERVICE_UNAVAILABLE )
114114 .entity ("Operation time out." ).build ());
115115
116- // new Thread(new Runnable() {
117- //
118- // @Override
119- // public void run() {
120- // String result = veryExpensiveOperation();
121- // asyncResponse.resume(result);
122- // }
123- //
124- // private String veryExpensiveOperation() {
125- // // very expensive operation that typically finishes within 1 second but can take up to 5 seconds,
126- // // simulated using sleep()
127- // try {
128- // Thread.sleep(5 * OPERATION_DURATION);
129- // return "DONE";
130- // } catch (InterruptedException e) {
131- // Thread.currentThread().interrupt();
132- // return "INTERRUPTED";
133- // } finally {
134- // LOGGER.info("Async long-running get with timeout finished on thread " +
135- // Thread.currentThread().getName());
136- // }
137- // }
138- // }).start();
116+ new Thread (new Runnable () {
117+
118+ @ Override
119+ public void run () {
120+ String result = veryExpensiveOperation ();
121+ asyncResponse .resume (result );
122+ }
123+
124+ private String veryExpensiveOperation () {
125+ // very expensive operation that typically finishes within 1 second but can take up to 5 seconds,
126+ // simulated using sleep()
127+ try {
128+ Thread .sleep (5 * OPERATION_DURATION );
129+ return "DONE" ;
130+ } catch (InterruptedException e ) {
131+ Thread .currentThread ().interrupt ();
132+ return "INTERRUPTED" ;
133+ } finally {
134+ LOGGER .info ("Async long-running get with timeout finished on thread " + Thread .currentThread ().getName ());
135+ }
136+ }
137+ }).start ();
139138 }
140139
141140 }
0 commit comments