Thanks for some very intresting comments ! I am not sure what the problem is with a static "singleton-like" factory ?
Yes, I agree with you that the threading part must be taken care of. If I remember the "double-checked locking" articles correctly (without refreashing my memory) one has to synchronize the instance() method ...and thats it ... So just synchronize it then ;-) I do agree with the problem of caching and server restarts. That can be a problem (and I resently read a java-tip workaround for this, I think it was at javaworld too), however the problems you mention are inherent to both util methods, irrespectively of if one uses Brett's all purpose or the ones generated by xdoclet. Best Regards Lukas > I found the links that I was writing about. Here they are: > > http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-double.html > http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-toolbox.html > http://www.javaworld.com/javaworld/javaqa/2002-04/01-qa-0412-doublelock.html > > They where at javaworld not java report. :) > > Beware! This is lowlevel stuff. > > Oystein > > -----Opprinnelig melding----- > Fra: Oystein Aadland [mailto:[EMAIL PROTECTED]] > Sendt: 29. november 2002 15:10 > Til: [EMAIL PROTECTED] > Emne: SV: [Xdoclet-user] caching homes in util > > > Hi > > I have seen problems with using this approach. Writing to static variables > is not allowed in the EJB standard. Most servers don't force you to follow > this rule, but there are reasons for why it has been stated. In Websphere 4 > cashing the homeinterface will result in an invalid reference if you restart > the bean that it points to. Another problem is the class loading policy of > the server that you are using. Worst case is one classloader per bean, which > would mean one static map per bean. Restarting or redeploying the bean or > application would not garantie that the static map would be reinitialised, > and would therefor hold old references. I know this was the case in an > application I made running on JBoss 3.0.1. > > Shortly, by breaking the ejb rules, you break portability og possibly the > application. There is no garanti that later versions or fixes of your chosen > server will continue to let you break the rules. > > I made a test program for JBoss 3.0.x to check for getting home and creating > session bean for local interfaces, and it was very quick, so I doubt that > there is much to gain by doing this. > > And if you really want to go for Brett's solution, make sure you do it > right. Brett writes that threading is not a problem, but he is terribly > wrong. The problem is not if you get two instances initially or not. The > problem is that you could get an ivalid instance. This is has to do with how > the prosessor organises read and writes. Shortly, it can reorganize read and > write as it "wants" between a read/write barriers (synchonization) which > could give you bizare and untracable problems if you dont play by the > synchronization rules. I tried to find the relevant articles on Java Report > web site, but I cannot find them. (The articles where about double phased > locking, but also applies to this problem). > > So my advice is: Don't do optimasations like this before you really need it, > check if it really is something to gain at all, and expect problems (at > least in the future). > > Best regards > Oystein > > > -----Opprinnelig melding----- > Fra: Lukas Severin [mailto:[EMAIL PROTECTED]] > Sendt: 29. november 2002 13:27 > Til: [EMAIL PROTECTED] > Emne: Re: [Xdoclet-user] caching homes in util > > > thanks for your input, Yes of course one is free to choose whatever one > wants, thats not an argument for pro nor con ;-) The obvious advantage with > Brett's solution is that you will have one utility class, the disadvantage > is the typecast you need to do. However you do know what you should cast > into since the lookup will take a the Home.class as an argument, so I dont > see that as a problem. Cashing homes is no problem, cashing Contexts > shouldnt be done. > > So personally I feel Brett's solution is better if none else has a good > argument against it .... > > Lukas > > By the way, what is PITA ? > > ----- Original Message ----- > From: "Aslak Hellesoy" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]>; "Lukas Severin" <[EMAIL PROTECTED]> > Cc: "xdoclet-user" <[EMAIL PROTECTED]> > Sent: Friday, November 29, 2002 12:04 PM > Subject: RE: [Xdoclet-user] caching homes in util > > > > > > > > > -----Original Message----- > > > From: [EMAIL PROTECTED] > > > [mailto:[EMAIL PROTECTED]]On Behalf Of Konstantin > > > Priblouda > > > Sent: 29. november 2002 11:47 > > > To: Lukas Severin > > > Cc: xdoclet-user > > > Subject: Re: [Xdoclet-user] caching homes in util > > > > > > > > > --- Lukas Severin <[EMAIL PROTECTED]> wrote: > > > > Instead of generating a bean util (for each bean) > > > > with xdoclet, would it not > > > > be better to use something like the following home > > > > factory ? > > > > > > > > > > > http://www-106.ibm.com/developerworks/java/library/j-ejb0924.html? > > > dwzone=jav > > > > > > Nobody prevents you from doing it. But it will > > > introduce dependency on external ( additional ) > > > classes > > > and this is PITA in most EJB environments. > > > > > > > What external classes are you talking about Konstantin? > > > > > XDoclet generates a class, and you use this utility. > > > It also caches home interfaces if you like. > > > > > > > In my previous post I incorrectly quoted Mathias that caching homes is > bad. > > I meant caching InitialContext is bad, due to cluster environments and > > servers going up and down. > > > > Aslak > > > > > And in my private extendet version it also provides > > > observer/observable list-wrappers for finders > > > and CRUD adapters and DataObject-strippers, which can > > > be chained together to provide sophisticated > > > infrastructure which comes handy to swing apps. > > > > > > regards > > > > > > ===== > > > Konstantin Priblouda ( ko5tik ) Freelance Software developer > > > < http://www.pribluda.de > < play java games -> http://www.yook.de > > > > < render charts online -> http://www.pribluda.de/povray/ > > > > > > > __________________________________________________ > > > Do you Yahoo!? > > > Yahoo! Mail Plus - Powerful. Affordable. Sign up now. > > > http://mailplus.yahoo.com > > > > > > > > > ------------------------------------------------------- > > > This SF.net email is sponsored by: Get the new Palm Tungsten T > > > handheld. Power & Color in a compact size! > > > http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en > > > _______________________________________________ > > > Xdoclet-user mailing list > > > [EMAIL PROTECTED] > > > https://lists.sourceforge.net/lists/listinfo/xdoclet-user > > > > > > > > ------------------------------------------------------- > > This SF.net email is sponsored by: Get the new Palm Tungsten T > > handheld. Power & Color in a compact size! > > http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en > > _______________________________________________ > > Xdoclet-user mailing list > > [EMAIL PROTECTED] > > https://lists.sourceforge.net/lists/listinfo/xdoclet-user > > > > ------------------------------------------------------- > This SF.net email is sponsored by: Get the new Palm Tungsten T > handheld. Power & Color in a compact size! > http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en > _______________________________________________ > Xdoclet-user mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/xdoclet-user > > > ------------------------------------------------------- > This SF.net email is sponsored by: Get the new Palm Tungsten T > handheld. Power & Color in a compact size! > http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en > _______________________________________________ > Xdoclet-user mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/xdoclet-user > > > ------------------------------------------------------- > This SF.net email is sponsored by: Get the new Palm Tungsten T > handheld. Power & Color in a compact size! > http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en > _______________________________________________ > Xdoclet-user mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/xdoclet-user ------------------------------------------------------- This SF.net email is sponsored by: Get the new Palm Tungsten T handheld. Power & Color in a compact size! http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en _______________________________________________ Xdoclet-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/xdoclet-user
