• 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

Problem in handling threading issue in servlet

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all.
Please tell me,what are the cases that i must handle the threading issues in MVC pattern.

Main servlet for handling request
Command classes for handling business logic
Jsp for view.

Since in my case Command class has instance method
public string execute (req,res){
call method of another class instance method()// for db access
}
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public string execute (req,res){
call method of another class instance method()// for db access
}
This is thread safe if it is a method in another class that is declared and instaniated within a service method. It is not thread safe if it is another method within a servlet class, or thread class.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
THIS IS YOUR THIRD WARNING
"faisal"-
Please adjust your displayed name to meet the
JavaRanch Naming Policy. This being your third notification, if you do not change it, your account could be closed.
You can change it
here.
Thanks! and welcome to the JavaRanch!
Mark
 
faisal khan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for answering the query.

i am still confuse that when i update/delete/add record in command execute method, it is still need of synchronization?
regards
Faisal Ishaque :roll:
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If that instance is local to the execute method, and it (the instance) does not use any objects that are shared by all requests, you do not have to synchronize since only one Thread can execute it.
Bill
 
faisal khan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks
Are u saying this...
It mean that DB may be share/ not share to all requests. If share (same table then use synchronize). if not then do not use synchronize..
What abt the session , when setting cart to session ? synchronize is required?
Faisal
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. If you only have one DB connection, it can't be used by multiple requests "at the same time" - read up on database connection pools
2. The purpose of a session is to keep the data for a particular client separate from other clients. Putting an object reference into a session does not need to synchronize on the session. However, note that a particular client may have multiple requests running "at the same time" - with frames, images, etc. so there are circumstances in which you have to synchronize on objects in a session.
Bill
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic