Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet & Filter

 
Mani Venkata Kanth
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HighLevel:
I have 3 filters configured for a servlet.I have to calculate average time taken by each filter.

Details:

1. I wrote a singleton object to maintain average times.

2. I am adding System.currentTime() in each filter doFilter() method start and end & at end setting these values to request.

3. In the servlet, I am adding these times & incrementing the requests count in the singleton object.

Till this point it is working properly.


But, In the first filter starting, I have to send this counters values by reading from singleton object to some monitoring logs.
Here is the problem.

Parellel requests causing inconsistent time values... Any ideas please???
 
Mike Zal
Ranch Hand
Posts: 144
Fedora Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My initial thought was to use the session id of the request to separate the requests, but a user with multiple tabs could still send simultaneous requests. You could try adding a UUID as an attribute to each request in the first Filter.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Think about different methods of storing time values, other than in an object, e.g database, text files, etc.
 
Paul Clapham
Sheriff
Pie
Posts: 20757
30
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see why parallel requests should cause a problem, unless perhaps your strategy was to pass this singleton object a starting timestamp and a finishing timestamp and ask it to calculate the difference.

If you had code in the filters which used local variables to calculate the running time and then pass the result to this singleton object, you would just need a tiny bit of synchronization in the singleton to remove the issue.
 
Mani Venkata Kanth
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, Thank you for your replies.

Paul, Yes... I am calculating start & end times in the filter and finally setting time diff to singleton. Yep, I did synchronization. It is hitting some performance issues.
Any more ideas please???

Paul Clapham wrote:I don't see why parallel requests should cause a problem, unless perhaps your strategy was to pass this singleton object a starting timestamp and a finishing timestamp and ask it to calculate the difference.

If you had code in the filters which used local variables to calculate the running time and then pass the result to this singleton object, you would just need a tiny bit of synchronization in the singleton to remove the issue.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic