java - Bad practice to wait for service to return? -


i'm calling spring web service takes approx 5 seconds return response. webservice call takes place within tomcat container prior being deployed websphere. i've been told developer call service should handled in separate java thread "bad practice have jvm stuck on 1 line of code long" in case stuck on line of code calls web service. disagree , think if web service takes 5 or 10 seconds complete that's fine, response received , code execution continue normal. right ?

i'd make 2 points:

  1. if subsequent computation depends on result of web service, don't have choice anyway , spawning new thread waste of resources;

  2. if call independent, there may reason offload separate thread. if 5 seconds not on own, may not (now or in future of codebase) point system pointlessly waits independent tasks complete. is practice let independent tasks run independently.

however, if call happening within application deployed tomcat container (this detail not clear question), generally bad practice web application spawn own child threads. tasks should submitted container-provided executor service, if there one.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -