Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to make JSP thread safe

 
JW Li
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The applicatin I was woring on was based on JSP model 1 (JSP is responsible for processing and displaying data) developed long time ago, with JSP pages directly accessing/updating some java beans (just simple JAVA object). The data processed are from user input and session. Based on the data processing result, I found some users' data has been mixed up with the other users. How can I make the least changes to make the application thread safe? Are local variables defined in JSP the cause of the mixed data? If not considering about the scope of changes, what's the best approach for developing a thread-safe web applications (any framework?) Thanks very much for any input!!
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You gotta track down and protect shared data.

One gotcha with JSPs and servlets is instance variables. If u declare variables using <%!Declare %>, it is translated in to instance variables in the converted servlet. Instance variables in jsps and servlets are by default shared by concurrent requests. So, be careful or avoid using the <%! DECLARE %> tag for variables.
I borrowed some wording from here: Discusssion on thread-safe jsps


Also check out this bit on JSP Synchronization Issues

[ June 09, 2004: Message edited by: Carol Enderlin ]
[ June 09, 2004: Message edited by: Carol Enderlin ]
 
JW Li
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Carol,

Thanks very much for your reply and the 2 links are really helpful:-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic