John Austin wrote:
Nothing to do with optimization. Just noticed some wrongness
that has the possibility to be pathological wrongness. Classes
should preclude the possibility of erroneous use. The subject
was making a URL resolver thread-safe. The class in question is
a source of state information needed later by the resolver.

Whoops! Was unsure about butting in the first place, certainly don't mean to offend. But since I already have, let me keep going and explain myself. :-)


The method is not necessarily pathological, right? If the intent of the method is to provide both a convenience method and a point of centralization (in case the parser is in the future overridden via one of the steps in the SAXParserFactory resolution mechanism or a hard-coded instance class name), it certainly has done so. It's legitimate for an app to want to know the class name of the SAX parser that will be produced by the app at any given moment.

Hence, since the method's existence has the potential to be legitimate (without checking its usages its impossible to know the exact contract since it is not documented), I assumed you were concerned with the performance implications of working around possible thread unsafety.

So, since SAXParserFactory is *not* thread-safe, the createParser() method ought to be synchronized and only if the synchronization presents a measurably unacceptable latency should caching mechanisms be considered (IMHO).

These are the thoughts that led to my earlier message, at least, feeble though they are. ;-)

Ben




[Lucky thing we didn't mention the dirty knife!]


On Fri, 2003-12-19 at 11:50, Ben Galbraith wrote:

Jeremias Maerki wrote:

Hmm, again, we could probably cache the value. Not very elegant, of
course, but how else do we get that value which is used in several
places?

Just an outsider's point-of-view: it probably doesn't make sense to waste time optimizing code like this unless a profiler indicates that it's a bottleneck.


Randomly searching through code for potential inefficiencies has widely been disproven as an effective optimization technique. ;-)

Ben


On 19.12.2003 13:57:26 John Austin wrote:


And of course, I missed the fact that the last method in the class
contains a pathological use. To get the name of this class, we create a
parser ?


 /**
   * Returns the fully qualified classname of the standard XML parser
for FOP
   * to use.
   * @return the XML parser classname
   */
  public static final String getParserClassName() {
      try {
          return createParser().getClass().getName();
      } catch (FOPException e) {
          return null;
      }
  }



Jeremias Maerki


Reply via email to