Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Synchronization?

 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

Can anyone please pictorially describe what is meant by synchronizing with service method is better than synchronizing on the context attribut itself?? Please help me guys?? I fail to understand as to how wehn we synchronize the service method will still give access to other servlets from the webapp to the context parameters. Please could anyone give a coded example.

Thanks in advance.
[ November 11, 2006: Message edited by: Bear Bibeault ]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Synchronizing on the service method would be completely contrary to the whole idea of servlet architecture. Anybody who advises this has not absorbed the basics and you should pay no attention to them.

Where did you see this suggestion?

Bill
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi William,

Thanks for the reply, I'm using the HFSJ and on page number xxv, point number 1 says, "Stop and Think" and to use my Brain(Only 200 grams availabe(lesser than the weight of the book)). I stopped on page 195 where Kim sits and asks to me "What do you think? Will it fix the problem I had??". I'm not able to visualize the system.

My understanding is that, if the service methos is synchronized, then only one request can be handled at a time. Now still when we synchronize on the servletcontext, only one request is going to have access to the servlet context. But what is the point here?? What if all the requests want to access the servletcontext attribute at the same time??? I mean, I don't understand the whole point of it. Please can you throw some light on it?? I would be very much thankful if anyone can get me this straight.

Thanks in advance.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic