Java Mailing List Archive

http://www.junlu.com/

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

Re: Static block issue.

Binildas C. A.

2004-09-29

Replies:

Inside App Servers, there is no guarantee on how many JVMs are there. But if
you assume that there is only one JVM (from vendor docs or from similar
source), then you can assume that Singleton pattern will hold good. Meaning,
static block will get executed only once (in a single JVM), and single
instance can be guaranteed for the deployment - Even if you have multiple
JVMs in app server, in a single JVM static block will be executed only once.

Using TimerTask inside App Server is not a recommended approach. Instead,
the best way is to javax.ejb.TimerService to hook entity beans, stateless
session beans, and message-driven beans to be registered for timer callback
events at a specified time, which will in turn flush the cache. But for
this, your App Server should have this EJB feature.

Again, caution of using "Cache inside app servers" - The moment we have more
than one JVM, there are cache synchronization issues, which can be solved
only out of trivial ways... Imagine the scenario of two web browser users
viewing different stock search results for the same query, at more or less
same instant (we cannot assume to which app server instance or to which JVM
inside same app server the query will be routed by web server load balancer)
!!

Binildas C. A.
Senior Technical Architect
http://www.infosys.com/setlabs/

----- Original Message -----
From: "Partha Ranjan Das" <partharanjan.d@(protected)>
To: <J2EE-INTEREST@(protected)>
Sent: Wednesday, September 29, 2004 12:58 PM
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.
> *********************************************************************
>
>
===========================================================================
> To unsubscribe, send email to listserv@(protected)
body
> of the message "signoff J2EE-INTEREST". For general help, send email to
> listserv@(protected)".
>

===========================================================================
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.