Editorial / Best Answer
satish_bakde
A JSP page is by default thread unsafe. That means when server finds a request to JSP, an instance is created and the request is processed. The code inside service method is processed. While in this process, if another request arrives, Server again starts executing the code inside service method for 2nd one. Multitasking is invoked to switch CPU between execution of these 2 threads created. Both are executing same code so, so if any thread changes a variable value and then second reads it, it will get changed one.
Though this is bad programming practise to have code like this, in case becomes unavoidable. At this time make page threadSafe="true". This will make service method synchronized and at a time only one thread will execute the code. other thread have to wait till that time. Assume how bad will be the response time of server when 100s of requests arrives at a time!
If we declare a page isThreadSafe="false" then how the page will act?
Profile Answers by tapan_1984 Questions by tapan_1984
Questions by tapan_1984 answers by tapan_1984
Editorial / Best Answer
satish_bakdeProfile Answers by satish_bakde Questions by satish_bakde
A JSP page is by default thread unsafe. That means when server finds a request to JSP, an instance is created and the request is processed. The code inside service method is processed. While in this process, if another request arrives, Server again starts executing the code inside service method for 2nd one. Multitasking is invoked to switch CPU between execution of these 2 threads created. Both are executing same code so, so if any thread changes a variable value and then second reads it, it will get changed one.
Though this is bad programming practise to have code like this, in case becomes unavoidable. At this time make page threadSafe="true". This will make service method synchronized and at a time only one thread will execute the code. other thread have to wait till that time. Assume how bad will be the response time of server when 100s of requests arrives at a time!
Related Answered Questions
Related Open Questions