Re: abstract constructor performance?
From: Tony Morris (not_at_telling.you)
Date: Fri, 13 Aug 2004 08:29:10 GMT
"Jeff" <email@example.com> wrote in message
> I've done some Google searches, searched my Safari subscription, and
> my books, but remain concerned about the following.
> My code uses three subclasses of an abstract class, but I'm concerned
> the performance hit of the call to the abstract constructor under load.
> Under heavy load, my code creates about 200 instances of the subclasses
> 1. If the abstract class has no constructor, then there's no call to it?
A flawed basis of reasoning - there is no such thing as an abstract class
that has no constructor (or any class).
> This question is simple,
The question is now unsubstantiated, so all answers from now on may be
> but I want to make sure there's no JVM magic behind
> the scenes.
> 2. If there is a call to an abstract constructor, do Java experts feel
> a significant performance penalty?
The call itself has a negligible performance penalty - if performance was a
requirement, you are looking in the wrong place. However, the act of
executing the constructor itself depends on the competence of the person who
wrote the abstract class. For example, it is general poor form to put a lot
of business logic in a constructor, especially in a subclassable class (all
abstract classes are subclassable unless they have only private
constructors). So, if someone erroneously wrote a constructor whose body was
of degraded performance, all subclasses are forced to "inherit" this
> BTW, I could create pools of these objects, but feel that negates a big
> advantage of Java.
This somewhat broad statement suggests that you might want to read up on
J2EE design patterns.
-- Tony Morris http://xdweb.net/~dibblego/