Bug 38596 - Unnecessary synchronization and garbage in DataSourceRealm
Unnecessary synchronization and garbage in DataSourceRealm
Product: Tomcat 5
Classification: Unclassified
Component: Catalina
Nightly Build
Other All
: P4 trivial (vote)
: ---
Assigned To: Tomcat Developers Mailing List
Depends on:
  Show dependency tree
Reported: 2006-02-09 17:55 UTC by Sandy McArthur
Modified: 2006-04-14 08:34 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Sandy McArthur 2006-02-09 17:55:11 UTC
DataSourceRealm.java declares two StringBuffers fields, preparedRoles and
preparedCredentials, that hold the SQL to be used. After these fields are
assigned they do not change but to use them StringBuffer.toString() must be
called. The toString method is synchronized and creates a new String instance
each time it's called.

The simple fix is to change those fields to Strings and update the start()
method, and remove the toString() calls in credentials(...) and roles(...) methods.

A better, more intrusive, fix is to take advantage of PreparedStatements like
JDBCRealm does.
Comment 1 Yoav Shapira 2006-04-14 15:34:47 UTC
Trivial, as you noted ;)  I did the simple optimization you suggested above, not
the more intrusive one.  If you really think there's good value in doing the
more intrusive one, please submit a patch that does it and reopen this issue. 
Thanks ;)