[Opensource] Réf. : RE: [Opensource] SimpleDateFormat

Raul DAVIDOVICH R.DAVIDOVICH at caconcology.com
Fri Mar 14 02:26:45 PST 2003


You can use a Singleton Pattern.. The idea is to create one object the
first time it's used, and then reuse it once and again.. here is a sample
code:

public class MyClass{

private static MyClass instance;

  private MyClass() {
  }

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



Notice the use of a private constructor.. this avoids you from constructing
a new object by calling it directly, and enforces the pattern

so when you'll call the object, you'll call it like this:

...

MyClass myClassObject = MyClass.getInstance();

...


If you want to go further, here are some useful addresses:


Patterns Home Page:
http://hillside.net/patterns/

The Design Patterns Java Companion:
http://www.patterndepot.com/put/8/JavaPatterns.htm


Design Patterns Synopses:
http://www.mindspring.com/~mgrand/pattern_synopses.htm


hope this helps


Regards
---------------------------------------------------
Raul Davidovich
Responsable Informatique
Cvitkovic & Associés Consultants

(33) 1 45 15 40 68
(33) 1 45 15 40 41 Fax
-------------------------------------------------------
http://www.caconcology.com


|---------+------------------------------->
|         |           "Ben Switzer"       |
|         |           <ben at site85.com>    |
|         |           Envoyé par :        |
|         |           opensource-admin at jco|
|         |           rporate.com         |
|         |                               |
|         |                               |
|         |           13/03/2003 17:44    |
|         |           Veuillez répondre à |
|         |           opensource          |
|         |                               |
|---------+------------------------------->
  >--------------------------------------------------------------------------------------------------------------------------------------------------|
  |                                                                                                                                                  |
  |       Pour :    <opensource at jcorporate.com>                                                                                                      |
  |       cc :                                                                                                                                       |
  |       Objet :   RE: [Opensource] SimpleDateFormat                                                                                                |
  >--------------------------------------------------------------------------------------------------------------------------------------------------|




That makes sense.

So Michael, how would I in a wrapper make use of the cache you've
already setup in JDBCUtil?

Ben

-----Original Message-----
From: opensource-admin at jcorporate.com
[mailto:opensource-admin at jcorporate.com] On Behalf Of Michael Rimov
Sent: Thursday, March 13, 2003 1:06 AM
To: opensource at jcorporate.com
Subject: RE: [Opensource] SimpleDateFormat


At 11:53 AM 3/12/2003 -0500, you wrote:
>SimpleDateFormat is not thread safe and if date formatting becomes a
>global resource then you are synchronizing a fairly expensive operation

>across the entire application. There are many reasons why you may want
>to format a date (logging, setting headers, etc.) on a per page basis
>and synchronizing on every page request is not a good thing.


Vincent,

What you've suggested is certainly a possibility.  One thing I've
noticed
in profiling, however, is that the expensive part of creating a
DateFormat
object is the creation and not the actual formatting.  By caching and
sharing date format instances (even synchronized), CPU time slices for
that
particular chunk of code dropped from 15% to 5%.  [Which is what I did
in
JDBC executor]

So given that, I think sharing a pool of SimpleDate instances would
ultimately reap the highest performance, and sharing a single one would
suffice over creating non-synchronized local copies up to considerable
scaling.

Hope this clarifies!
                                                 -Mike




_______________________________________________
Opensource mailing list
Opensource at jcorporate.com
http://mail.jcorporate.com/mailman/listinfo/opensource
Archives: http://mail.jcorporate.com/pipermail/opensource/

_______________________________________________
Opensource mailing list
Opensource at jcorporate.com
http://mail.jcorporate.com/mailman/listinfo/opensource
Archives: http://mail.jcorporate.com/pipermail/opensource/








More information about the Opensource mailing list