开发者

How to catch DeadlineExceedException in GAE/J?

开发者 https://www.devze.com 2022-12-17 08:31 出处:网络
How do you go about catching this exception in a servlet that takes longer than 30 seconds? Thanks!开发者_StackOverflow社区You can use a normal try-catch around your code and catch the DeadlineExceed

How do you go about catching this exception in a servlet that takes longer than 30 seconds?

Thanks!开发者_StackOverflow社区


You can use a normal try-catch around your code and catch the DeadlineExceededException:

import com.google.apphosting.api.DeadlineExceededException

try {
  // your code
} catch (DeadlineExceededException e) {
  // do something here to handle the exception in a user-friendly way
}

Do remember that your time available after catching the DeadlineExceededException is limited. So you can't execute a lot of code inside the catch, because it will generate a HardDeadlineExceededError after a short period (generally < 1 sec).

So use it wisely and just return a message to user or do a quick cleanup to rollback anything if necessary.

0

精彩评论

暂无评论...
验证码 换一张
取 消