Results 1 to 5 of 5
- 08-04-2011, 02:07 PM #1
Member
- Join Date
- Jul 2011
- Posts
- 6
- Rep Power
- 0
Synchronization of ServletContext Object
Hi All,
-- I am trying to make the ServletContext synchronize because when 2 or more clients, are trying to modify the same servletcontext attributes, then that will be a problem. Because Servlet A tries to set context attribute as context.setAttribute("A","test1"); and Servlet B tries to set context attribute as context.setAttribute("A","B related code"); It could happen because Servlet B doesn't know that Servlet A also has the same attribute. That will be a problem as now servlet A will get the output as "B related Code" instead of "test1" if both acces the same code at a time, and Servlet B changes before servlet A recieves the response
--If clientA write synchronize(getServletContext()) and in that he sets 2 attributes context.set("A","test1") and context.set("B", "test2"), clientA first gets the lock on the ServletContext object.
--But another person (clientB) from another servlet also try to access the synchronize(getServletContext()) method and try to replace the values of the attributes "A" and "B" when clientA's lock is still there.
Will clientB can access it...? I think no, because clientA has already lock
.
-- Now my question is, will clientB will able to run his Servlet or any other client can run their servlets, on the same context , as clientA has already a lock on contextobject. And for the servlet to run, the servlet should be on running on that context itself and since the lock has already been obtained for that context, how can other client requests be servered for anyting ( I meant not only for the attributes but any other code in it), until clientA releases the lock ?
NOTE: I think that getServletContext() will return the same context reference always instead of creating with the "new" operator each time. i.e, singleton object.
Please clarify me regarding this..!
- 08-04-2011, 03:06 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Why are you using the ServletContext to hold data like that?
There is one per web app.
- 08-04-2011, 03:06 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Why are you using the ServletContext to hold data like that?
There is one per web app.
- 08-04-2011, 05:22 PM #4
Member
- Join Date
- Jul 2011
- Posts
- 6
- Rep Power
- 0
I got through this scenario when I was making some R & D. So I am looking for the clarification, on how to proceed if we are in this type of scenario. Ofcourse, we can go with request, session or any properties file or database. But anyway it should be possible from the context also. That's the reason I am looking for some way..!
- 08-04-2011, 05:56 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Similar Threads
-
need help in locking or synchronization
By samanyu in forum New To JavaReplies: 24Last Post: 07-06-2011, 06:19 AM -
java RMI and synchronization
By guest_user in forum New To JavaReplies: 15Last Post: 07-05-2011, 12:28 AM -
Threads and Synchronization
By ASADUN in forum Threads and SynchronizationReplies: 4Last Post: 12-18-2009, 07:00 AM -
i need help for ServletContext
By samiahmed in forum Java ServletReplies: 2Last Post: 09-24-2008, 10:46 AM -
Animation Synchronization
By dreadrocksean in forum Advanced JavaReplies: 5Last Post: 08-08-2008, 02:56 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks