This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes Web Application Framework Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Web Application Framework" Watch "Web Application Framework" New topic
Author

Web Application Framework

Ashwini Srivastava
Greenhorn

Joined: Feb 01, 2006
Posts: 1
Hi all,

I have created a servlet based on the Web Application Framework as suggested by SUN
( link : http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/web-tier/web-tier5.html [ Look under Web Tier MVC Controller Design ].

The controller has been designed using the Hashmap ( as discussed in the above link and Code is as below )

public class ControllerServlet extends HttpServlet {
private HashMap actions;
public void init() throws ServletException {
actions = new HashMap();
CreateUserAction cua = new CreateUserAction(model);
actions.put(cua.getName(), cua);
//... create and add more actions
}
public void doPost(HttpServletRequest req,
HttpServletResponse resp)
throws IOException, ServletException {

// First identify operation "op" from URL.
// method getOperation() is defined elsewhere.
String op = getOperation(req.getRequestURL());
// Then find and execute corresponding Action
Action action = (Action)actions.get(op);
Object result = null;
try {
result = action.perform(req);
} catch (NullPointerException npx) {
//... handle error condition: no such action
}
// ... Use result to determine next view (see next section)
}
//... other methods...
}


The question pertains to :

If two users are coming simultaneously then, they will be using the same object from ACTION HASHMAP and if "perform" is called then the same object "perform" method will be called. I do see that request and response object will be unique for each request in "doPost()". But keeping in mind that Servlet is not thread safe then one request, response object will overwrite the other persons request response object.

Can anybody explain that my understanding is correct and if 10s of request will come simultaneously then each will perform uniquely or not ???

Warm Regards
Ashwini
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8903

Ashwini,
Each request will have a different request/response objects. No issues. What you need to worry is if there are objects which are shared across requests(thread).

I noticed that you are catching NullPointerException.It is an unchecked exception so avoid catching NullPointerException.


Groovy
dema rogatkin
Ranch Hand

Joined: Oct 09, 2002
Posts: 294
perform can be synchronized though


Tough in space?, <a href="http://tjws.sf.net" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="http://mediachest.sf.net" target="_blank" rel="nofollow">Check it here.</a><br /><a href="http://7bee.j2ee.us/book/Generics%20in%20JDK%201.5.html" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="http://7bee.j2ee.us/bee/index-bee.html" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="http://7bee.j2ee.us/addressbook/" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="http://searchdir.sourceforge.net/" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Web Application Framework
 
Similar Threads
httpsessionActivationlistener
MVC without Struts: A doubt
User Session - Servlet or SFSB
sun example Model datatype
Model 2 Controller/Action Design