Re: abstract constructor performance?

From: Tony Morris (not_at_telling.you)
Date: 08/13/04


Date: Fri, 13 Aug 2004 08:29:10 GMT


"Jeff" <jeffdrew@bellatlantic.net> wrote in message
news:XkLRc.2242$AA1.416@trndny06...
> I've done some Google searches, searched my Safari subscription, and
checked
> my books, but remain concerned about the following.
>
> My code uses three subclasses of an abstract class, but I'm concerned
about
> the performance hit of the call to the abstract constructor under load.
> Under heavy load, my code creates about 200 instances of the subclasses
per
> second.
> 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
speculative.

> 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
it's
> 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
performance penalty.

>
> 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/


Relevant Pages

  • Re: Factory method
    ... > factory method in my abstract class that creates subclasses. ... > constructor in my subclasses must be able to call the constructor in my ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Factory method
    ... > factory method in my abstract class that creates subclasses. ... > constructor in my subclasses must be able to call the constructor in my ...
    (microsoft.public.dotnet.languages.csharp)
  • Factory method
    ... I have an abstract class, and a set of classes that inherit from my abstract ... factory method in my abstract class that creates subclasses. ... constructor in my subclasses must be able to call the constructor in my base ... For the factory method in my abstract class to call the constructor ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: extending abstract class
    ... > public FileCommand{//can abstract class throw extension? ... > public class ByteChar extends FileCommand { ... it means that this constructor will call the constructor of the ... As Strings are object a direct comparison compares on a reference ...
    (comp.lang.java.help)
  • Re: extending abstract class
    ... > public FileCommand{//can abstract class throw extension? ... > public class ByteChar extends FileCommand { ... it means that this constructor will call the constructor of the ... As Strings are object a direct comparison compares on a reference ...
    (comp.lang.java.help)