user3085390
user3085390

Reputation: 187

Java Servlet initialization fail

If we are using a resource in servlet init method and during initialization it failed to reach that resource but we know that after sometime resource will be available. What shall we do in this case?

  1. throw unavailable exception
  2. don't do anything once a request comes for this servlet it might start working
  3. do necessary stuff like try/catch and provide fallback logic

Any other suggestion?

Upvotes: 0

Views: 1597

Answers (2)

jiangchunzhi
jiangchunzhi

Reputation: 81

I think, it depend on whether the resource is required for user's request. If it is required, you must initialize the resource before process user's request. If it is not required, you can skip the resource. You can also log the request in your database or log file. When the resource is available, you can invoke operation according to the log and modify status of the data which you stored.

Upvotes: 1

Vidya
Vidya

Reputation: 30300

It's a strange situation to accept requests before everything is available, but regardless, this is an example of a fault exception. You should throw an exception and have it bubble up to the "fault barrier," which is where you handle the exception. For example, you might log the exception and let the user know to check back later.

This is in contrast to contingency exceptions, which are recoverable and should be handled in such a way as to allow the user to move forward.

By the way, I didn't come up with this approach. Barry Ruzek did.

Upvotes: 1

Related Questions