I have a servlet which does the following:
- Gets a set of data from a webservice
- Gets a set of data from the local database.
- Merges the two sets and returns the results.
Actually little of this is done within the servlet code itself, but the servlet calls Java classes which do the above.
Since most of the time is spent waiting for both the webservice and database, I am considering performing the two concurrently: put the webserivce call in a thread, get the data from the Database, and then waiting until the webservice is done before continuing. This seems like it should work fine, but I often hear that launching threads from servlets is a bad idea? I am having trouble seeing how this situation would lead to problems. Any help would be great (using tomcat 6 on linux). Thanks!
I dont see anything wrong with it and have often seen threads being started from a servlet itself. You use-case is good justification for starting threads within servlet.