The Artima Developer Community
Sponsored Link

Java Answers Forum
singleton performance

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Martijn Kelder

Posts: 1
Nickname: martijn101
Registered: Jul, 2006

singleton performance Posted: Jul 26, 2006 11:50 PM
Reply to this message Reply
Advertisement
We made thousand (I = [0 .. 999]) singletonI classes.

public class singletonI extends abstractclass {
private static singletonI instance;

private singletonI(){}

public int getValue(){
body;
}

public static singletonI getInstance() {
if (instance == null) {
instance = new singletonI();
}

return instance;
}
}

Each class has a getValue method. The body of the getValue
method can either be complex or simple. A simple body means that
the method returns the value 10 (return 10;). A complex body is
a body that uses other classes' getValue methods to
calculate a complex value, which it subsequently returns (for example return
singletonI.getInstance().getValue() + singletonI.getInstance().getValue();)

We also made one large singleton class in which we
store all methods of the thousand separate classes. The compelex getValue methods
invoke other getValue methods which are now stored in the same class.

Could someone explain me why the large class alternative is faster than the
thousand classes alternative? If take 10 threads the difference between the two alternatives
is even bigger.

java version "1.4.2_11"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_11-b06)
Java HotSpot(TM) Client VM (build 1.4.2_11-b06, mixed mode)

Topic: Handling Redirects Previous Topic   Next Topic Topic: help for Text to Speech synthesizer!!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use