java - Any reason to use Spring @Async on external calls -


when @async applied method making external call, tomcat request thread able handle next incoming request. happens when external service returns?

if same thread pool used, theoretically when external service returns, threads could busy , have wait free thread - means using @async can slower in case.

i'm asking see benefits of @async , confirm understanding.

in calling @async method doesn't free tomcat thread - need combine e.g. deferredresult<> or asynccontext/startasync() - asynchronous method run on thread separate pool (configurable via spring), , original thread can freed process request.

if tomcat thread pool processing other, shorter-lived types of request well, allows many of these requests processed while waiting slow external request complete, that's immediate benefit. if other requests frequent enough and/or intensive enough they're maxing out tomcat thread pool, you're going have performance issues anyway, async threads or not.

if on other hand tomcat request threads firing off these external calls asynchronously, unlikely tomcat pool exhausted before hit other limits. advantage in case can have more requests in parallel threads in tomcat thread pool.

all of above assumes using deferredresult<>, asynccontext/startasync() etc. free tomcat thread, if you're not doing there still cases @async can useful, e.g.

  • you want make multiple external requests can run in parallel , may take significant time execute - see github api example in spring guides
  • you have significant processing locally , external request can execute in parallel that. in case fire off @async request, local work, wait request finish.

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -