GeekInterview.com
Series: Subject: Topic:
Question: 14 of 199

If we declare a page isThreadSafe="false" then how the page will act?

Asked by: tapan_1984 | Member Since Feb-2007 | Asked on: Nov 27th, 2007

View all questions by tapan_1984   View all answers by tapan_1984

Editorial / Best Answer

Answered by: satish_bakde

View all answers by satish_bakde

Member Since Dec-2007 | Answered On : Dec 7th, 2007

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!

Showing Answers 1 - 3 of 3 Answers
satish_bakde

Answered On : Dec 7th, 2007

View all answers 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!

Yes  9 Users have rated as useful.
  
Login to rate this answer.

Yes which is why we use servlets instead of Jsp's for handling the web requests...

  
Login to rate this answer.
pradeep23

Answered On : Jun 17th, 2008

View all answers by pradeep23

nice answer

Yes  2 Users have rated as useful.
  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.