Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DB calls from Servlet Filter vs Action class

 
Sudheerv Babu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sudheerv Babu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic