Issue
I am wondering how, in concept, the web requests different from threads that I can create in application itself? Do they suffer from same problems as threads do (locking, have to make state-objects thread - safe)
Are various HTTPRequests in any java - jackson (rest apis) application synchronized by web-server automatically? Are these requests not like threads and suffer from the possibility of interfering with states of various classes which are handling these web-requests? Or, is this something that application developers have to manage themselves? i.e. they do need to either synchronize or make these jackson servlets thread-safe otherwise?
Thanks
Solution
Servlets should be written as if they were single threaded. Each HTTP request coming in will be handled in a separate thread.
This means no shared mutable state in servlet classes.
If your servlet has no private data members and all operations are performed on parameters that are passed in or local objects, you're thread safe. No synchronization needed.
Shared state has to be thread safe.
Answered By - duffymo
Answer Checked By - Marilyn (JavaFixing Volunteer)