• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Online Reservation - doubt

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Shaik Vali wrote:SingleThreadModel interface .



Which is Deprecated . use synchronize block for mutable data .
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic