[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Static Method performance
What happens to order of execution?
Example -
Say there are 500 objects which have to use a certain method X ( exampled
below).
If i make X as static then 499 objects would have to queue up for access to
the method, while if i make X an instance variable then each of 500 objects
would have their own copy of the X's object and hence a copy of X.
public class Y
{
String[] data = new String[100];
public String[] X(int i)
{
return (data[i],data[i+1].....data[i+10]);
}
}
I understand that if i make X as static then data would also be a static
variable.
Hope i have been able to express my question correctly.
Thanks
Mayank
----- Original Message -----
From: "Brian Lee" <brian_a_lee@hotmail.com>
To: <aggarwalmayank@hotmail.com>; <ajug-members@www.ajug.org>
Sent: Wednesday, February 27, 2002 1:34 PM
Subject: Re: Static Method performance
> I've seen about a 15% increase in performance between the same method
static and non-static. The test is pretty basic (do this 1000000 times and
time it) so I don't have real-world data.
>
> The only downside I've experienced with static methods is that if your
class is implementing an interface, the interface defined methods can't be
static.
>
> Other than this, I make as many methods as possible static (and final) for
performance reasons. Since most of the code I write doesn't go into a
published API, I declare final and then change it if extending becomes
necessary.
>
> BAL
>
> >From: "Mayank Aggarwal" <aggarwalmayank@hotmail.com>
> >To: <ajug-members@www.ajug.org>
> >Subject: Static Method performance
> >Date: Wed, 27 Feb 2002 13:02:57 -0500
> >MIME-Version: 1.0
> >X-Originating-IP: [156.63.134.4]
> >Received: from [66.45.18.180] by hotmail.com (3.2) with ESMTP id
MHotMailBE466B1300274004318B422D12B487C50; Wed, 27 Feb 2002 10:06:24 -0800
> >Received: (from list@localhost)by ajug.org (8.11.2/8.11.2) id
g1RJAS514324;Wed, 27 Feb 2002 14:10:28 -0500
> >From ajug-members-request@ajug.org Wed, 27 Feb 2002 10:07:33 -0800
> >Resent-Date: Wed, 27 Feb 2002 14:10:28 -0500
> >X-Priority: 3
> >X-MSMail-Priority: Normal
> >X-Mailer: Microsoft Outlook Express 5.50.4807.1700
> >X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700
> >Message-ID: <OE48P1f3L0zGSOpD0mA0000c25f@hotmail.com>
> >X-OriginalArrivalTime: 27 Feb 2002 18:03:41.0818 (UTC)
FILETIME=[16F64DA0:01C1BFB9]
> >Resent-Message-ID: <Fvd7UB.A.ufD.k8Sf8@ajug.org>
> >Resent-From: ajug-members@ajug.org
> >X-Mailing-List: <ajug-members@ajug.org> archive/latest/1
> >X-Loop: ajug-members@ajug.org
> >List-Post: <mailto:ajug-members@ajug.org>
> >List-Help: <mailto:ajug-members-request@ajug.org?subject=help>
> >List-Subscribe: <mailto:ajug-members-request@ajug.org?subject=subscribe>
> >List-Unsubscribe:
<mailto:ajug-members-request@ajug.org?subject=unsubscribe>
> >Precedence: list
> >Resent-Sender: ajug-members-request@ajug.org
> >
> >How does static method affect performance in Java?
> >
> >I understand that all the method variables are created on Stack and hence
each calling party gets its own stack of variables, hence there should not
be problems of concurrency as long as only method local variables are
manipulated.
> >
> >What other reasons are there for not using a static methods ?
> >
> >
> >Thanks
> >Mayank
>
>
>
>