views:

60

answers:

2

I am building a webservice on Weblogic 10.3.3 and I am using a servlet filter to log the request to a database. I do not want the filter to slow down the call to the webservice. So I actually have 2 questions.

1) Does the filter, or can I make the filter do the logging on a separate thread? if so how?

2) is there a way I can dynamically turn the filter on or off without having to redeploy code.

Thanks

+4  A: 
  1. Filter is executed by the thread assigned to your request. You can create a FutureTask to do logging if you wish, but there's nothing built into the Filter to allow you to do such a thing. If you're using Log4J, you can log to a queue and unload your app that way.
  2. Filters are added in web.xml, so you can't turn them off or on that way. If there's a JMX bean inside that does the work, perhaps you can use the JMX console to turn its function off and on.

You might be guilty of premature optimization here. If you logging or filtering stuff is going to be a problem, I'd wait until I had evidence to prove it before I'd start redesigning to fix it.

duffymo
Indeed, profile first! The bottleneck may for instance actually be an unpooled DB connection. As to point 2, another option is runtime checking of a propertiesfile in classpath. But that may also slowdown things. As does basically every line of code.
BalusC
A: 

A lot of logging software supports "asynchronous logging", where a log event is put into a queue very quickly, and then a separate thread writes them to persistent storage as soon as it can. The drawback here is that you are more likely to lose messages if your app crashes while events are still in the queue. The overall overhead is slightly higher too, since you have multiple threads coordinating with each other.

Additionally, many logging frameworks have a "watch configuration" option that periodically checks a configuration file. This allows you to enable or disable a logger on a "hot" system.

What logging library are you using?

erickson