Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » J2EE Interest »

Re: Static block issue.

Partha Ranjan Das

2004-09-29

Replies:

Hi Manish,

Using a singleton object in ejb tier for maintaining an updatable cache is
OK only if you do not have any web tier. but you have to externally
synchronize in that object to do any modefication if you are using
non-synchronized collection classes. Again using thread primitives in ejb
tier is not good. So you may use some synchronized classes like
ConcurrentHashmap which do not need external synchronization. I will always
prefer an "application" scope object in web tier if that is possible. By the
way, why do you need a cache in the ejb tier?

A2. As for performance, aren't resources in theserverside.com not
sufficient? Some of the established patterns like servicelocator,
compositeentity have a significant amount of performance consideration in
their design.

A3. What is the use of re-initialising the same final object to same values
over and over again? They can very well be initialized outside the loop. I
do not know if I am missong something?

Regards,
Partha

> ----------
> From:      Manish Malhotra[SMTP:manish.mmalhotra@(protected)]
> Sent:      Wednesday, September 29, 2004 1:50 PM
> To:  'Partha Ranjan Das'; J2EE-INTEREST@(protected)
> Subject:    RE: Static block issue.
>
> He thanks Partha for your time.
> My Cache is singleton object and it lies in Business tier and not in Web
> tier. So, Does it seems fine?
>
> And can u give ur feedback on one more issue which I posted earlier also
> but
> no body reponded.
> Q was:
>
> Please give me the list or some important points for the core java / ejb /
> jsp code performance enhancement.
>
> And one basic question.
> Please see the following is the code snippet
> :
>
>
>          for (int i = 0; i < array.length; i++)
>          {
>               ** final String priority = (String)
> dataMap.get(SMSGConstants.SMSG_MESSAGE_PRIORITY);
>               LogWriter.logDebugMessage("priority: " + priority);
>               // Get the app name
>               ** final String appName = (String)
> dataMap.get(SMSGConstants.SMSG_APPLICATION_NAME);
>               LogWriter.logDebugMessage("appName: " + appName);
>               LogWriter.logDebugMessage("CountryCOde: " +
> SMSGUtil.getIntValue(SMSGUtil.checkNull((String) dataMap.get
> (SMSGConstants.SMSG_COUNTRY_ISD_CODE))));
>               // Get the CC
>               ** final int countryISDCode =
> SMSGUtil.getIntValue(SMSGUtil.checkNull((String) dataMap.get
> (SMSGConstants.SMSG_COUNTRY_ISD_CODE)));
>               SPConfigKey spConfigKey = new
> SPConfigKey(countryISDCode, appName,
> priority);
>          }
> ** Important lines **
>
> The point which I want to ask is as I declared the variables priority,
> appName, countryISDCode as final and in this loop.
> Now consider this case If I declare these vars outside this loop and
> obviously not final.
>
> Performace and space vise which is better?
>
> For the former type I give favour because I think that if I declare a
> variable. in a block( in this case its a loop) then as soon as one
> iteration
> cmopletes all its vars are eligible for garbage collection. So, whatever
> the
> no. of var. or objects created in the loop all are eligible for GC. Is it
> correct?
>
> And one more question If 'll not declare these vars as const then what's
> the
> difference. Is final object / variable takes less space or performance
> wise
> good.
> I dont have any idea about this.
>
> Please do give the answers so that we can start this interesting topic
> thread.
> Many Thanks.
>
> regards,
> Manish
>
>
>
> -----Original Message-----
> From: Partha Ranjan Das [mailto:partharanjan.d@(protected)]
> Sent: Wednesday, September 29, 2004 12:59 PM
> To: J2EE-INTEREST@(protected)'
> Subject: RE: Static block issue.
>
>
> This should work fine in the given case for the purpose of running the
> static code only once and starting the timertask...
>
> But where is your cache lying: in the web tier or ejb tier?
>
> Again, is the cache a singleton object or an "application" object of the
> web
> tier?
>
> Regards,
> Partha
>
> > ----------
> > From:     Manish Malhotra[SMTP:manish.mmalhotra@(protected)]
> > Sent:     Wednesday, September 29, 2004 12:38 PM
> > To:      J2EE-INTEREST@(protected)
> > Subject:   Static block issue.
> >
> > Hi All,
> >
> > If Im creating an object from a Session Bean.
> > Singleton pattern is used to create this Object.
> > There is one static block in this class.
> >
> > Now my question is if n no. of beans create the object of this class in
> > the
> > same JVM. Then its static block would be called only once.
> > Is this correct? Please let me know from your all good side.
> >
> > And Im using this class to start one TimerTask thread to refresh my
> cache
> > after fixed amount of delay. Please comment on this design also.
> > Actually Bean is the entry point of my application so I cant start this.
> I
> > can call another helper class to start the thread but its more or less
> > same.
> >
> > So, plz give me your comments / help as its highly required.
> >
> > Many Thanks.
> > regards,
> > Manish
> >
> >
> >
> > Manish Malhotra
> > Patni Computer Systems Ltd
> > Vashi Infotech Park, Tower-1, Unit No.:141/151, 11P
> > Above Vashi Railway Station, Vashi
> > Navi Mumbai-400705, India
> > Tel: +91 22 55910849 Extn: 235
> > Fax:+91 22 55910855
> >
> >
> ==========================================================================
> > =
> > To unsubscribe, send email to listserv@(protected)
> > body
> > of the message "signoff J2EE-INTEREST". For general help, send email to
> > listserv@(protected)".
> >
> *********************************************************************
> Disclaimer: The information in this e-mail and any attachments is
> confidential / privileged. It is intended solely for the addressee or
> addressees. If you are not the addressee indicated in this message, you
> may
> not copy or deliver this message to anyone. In such case, you should
> destroy
> this message and kindly notify the sender by reply email. Please advise
> immediately if you or your employer does not consent to Internet email for
> messages of this kind.
> *********************************************************************
>
>
*********************************************************************
Disclaimer: The information in this e-mail and any attachments is
confidential / privileged. It is intended solely for the addressee or
addressees. If you are not the addressee indicated in this message, you may
not copy or deliver this message to anyone. In such case, you should destroy
this message and kindly notify the sender by reply email. Please advise
immediately if you or your employer does not consent to Internet email for
messages of this kind.
*********************************************************************

===========================================================================
To unsubscribe, send email to listserv@(protected)
of the message "signoff J2EE-INTEREST". For general help, send email to
listserv@(protected)".
©2008 junlu.com - Jax Systems, LLC, U.S.A.