2017-04-09 7 views
1

は、私は次の記事を見つけた:Spring MVCの3.2プレビュー:サーブレット3をご紹介し、非同期サポートspring mvcでの結果のタイムアウトの使用方法は?

例:

@RequestMapping("/quotes") 
@ResponseBody 
public DeferredResult<String> quotes() { 
    DeferredResult<String> deferredResult = new DeferredResult<String>(); 
    // Add deferredResult to a Queue or a Map... 
    return deferredResult; 
} 


// In some other thread... <-- important phrase 
deferredResult.setResult(data); 
// Remove deferredResult from the Queue or Map 

しかし、結果は1分以内に設定されていなかった場合、私は場合に必要 - あるべきエラーresul戻ってきた。

私の要件に応じてこの例を変更するにはどうすればよいですか?

答えて

2

DeferredResultには、要件に使用できるコンストラクタがあります。

/** 
     * Create a DeferredResult with a timeout value and a default result to use 
     * in case of timeout. 
     * @param timeout timeout value in milliseconds (ignored if {@code null}) 
     * @param timeoutResult the result to use 
     */ 
     public DeferredResult(Long timeout, Object timeoutResult) { 
      this.timeoutResult = timeoutResult; 
      this.timeout = timeout; 
     } 
関連する問題