GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  J2EE  >  JSP
Go To First  |  Previous Question  |  Next Question 
 JSP  |  Question 303 of 306    Print  
If we declare a page isThreadSafe="false" then how the page will act?

  
Total Answers and Comments: 3 Last Update: June 17, 2008     Asked by: tapan_1984 
  
 Sponsored Links

 
 Best Rated Answer
Submitted 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!

Above answer was rated as good by the following members:
ashlesh garate, Satheeshgeek, prasadgelli, pradeep23, suresh_mech05, phdsong
December 07, 2007 02:29:30   #1  
satish_bakde Member Since: December 2007   Contribution: 1    

ANS: If we declare a page isThreadSafe="false" then how the page will act?
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!

 
Is this answer useful? Yes | NoAnswer is useful 6   Answer is not useful 0Overall Rating: +6    
March 10, 2008 03:53:27   #2  
bharaniprasanth Member Since: February 2008   Contribution: 46    

RE: If we declare a page isThreadSafe="false" then how the page will act?
Yes which is why we use servlets instead of Jsp's for handling the web requests...
 
Is this answer useful? Yes | No
June 17, 2008 08:42:50   #3  
pradeep23 Member Since: January 2008   Contribution: 1    

RE: If we declare a page isThreadSafe="false" then how the page will act?
nice answer
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape