wood burning stoves 2.0*
The moose likes Websphere and the fly likes DB calls from Servlet Filter vs Action class 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 » Products » Websphere
Bookmark "DB calls from Servlet Filter vs Action class" Watch "DB calls from Servlet Filter vs Action class" New topic
Author

DB calls from Servlet Filter vs Action class

Sudheerv Babu
Greenhorn

Joined: Aug 07, 2008
Posts: 5
Hi,
I have a situation where we calls DAO in servlet filter for user authorization. During the load test we realizes that this things become bottleneck and spawn multiple threads results in crashing server environment. But when we remove this call from filter and do the same thing after chain.doFilter() method, like in Action class it does not create same problem.
What I want to know, is there a difference in handling database calls in Filter verses in POJO?

Thanks in advance.
Sudheerbabu
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

A filter will be invoked for each request to the mapping for which it is configured. Why on earth would you need to authenticate the user on each and every request? Once the user is authenticated, simply indicate as such in the session and stop beating the DB to death.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sudheerv Babu
Greenhorn

Joined: Aug 07, 2008
Posts: 5
I wish it was just authentication but this is about authorization in the application. In our application user deals with case ids where he has access to limited number of cases. So, whenever he makes request with some case id, we check if he is authorized to play with that case_id in the filter itself which involves DB call.
My problem is it crashes server when i do this activity in the filter not anywhere else. So, wondering if web container handles it different way.

Thanks
Sudheerbabu
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

No, code is code. Do you observe a greater number of DB calls when there are problems than when there are not?
Sudheerv Babu
Greenhorn

Joined: Aug 07, 2008
Posts: 5
Number of db calls are same in both the cases. Actually, I am running load test on the application with some 500 vusers. DB queries are optimized and has no load on db. When I have this filter code which makes queries for authorization check, after a while everything slows down and throws a websphere core dump showing thread contention in websphere. DB connection pool is quite enough to handle required connections by this load test. When I move this db calls from filter to action class layer I don't see this issue. So, again wondering why this happens only when in servlet filter.

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

It should make no difference whether the code runs as a filter invocation or in an action class, so I cannot account for you observations. I'm moving this over to the websphere forum for those more familiar with websphere to comment.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: DB calls from Servlet Filter vs Action class
 
Similar Threads
Need Solution for accesing Action servlet only on Submit
servlet filter and struts
avoiding initialization of hibernate objects
Filter or ActionServlet
using filters with struts