Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Online Reservation - doubt  RSS feed

 
Shaik Vali
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys ,

I have a doubt from long back, if I am wrong please correct me.

# For multiple requests to a servlet ,instead of creating multiple instances webcontainer will create one copy for each request thread,

so each thead will have it's own copy.


# Servlets are not thread-safe , then how they will work in Railway reservation where 100s clients used to access.

# Please give some code regarding this.


Thanks a lot

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to write your servlets to be thread safe. That means not storing anything in instance variables and avoiding other thread-issue behaviors.

You can store local info in the request scope, which is thread-safe.
 
Shaik Vali
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear Bibeault ,

many thanks for reply .

You mena to say that make the servlet to implent SingleThreadModel interface or use Sycronized keyword or Synchronized block

right ..? then only one therad will allowed at a time , how abt other clients/threads. The thread should wait until the completion of previous thread sthen it will

take too much time to give the access to others. If I am wrong please correct me.

Please reply me.

Thanks a lot .
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shaik Vali wrote:SingleThreadModel interface .


Which is Deprecated . use synchronize block for mutable data .
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shaik Vali wrote: You mena to say that make the servlet to implent SingleThreadModel interface or use Sycronized keyword or Synchronized block

No. Just write the servlet correctly. No instance variables, for example.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!