comp.lang.java.programmer http://groups-beta.google.com/group/comp.lang.java.programmer [EMAIL PROTECTED]
Today's topics: * Struts Server-Side Form Validation - 4 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e8d7503f3780d747 * Need some help with Java application. - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f2f2f1701ec9cacd * simple prog in javax.comm not running - 3 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6e4091413a3cdbf3 * JSP EL and explicit error messages - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/65e5ee92bf562a84 * J2ee example in Jboss - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d283362ec4397f86 * Setting Java Virtual Memory - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/991635c2a770e75c * How to add Java .properties files to Apache Tomcat 4.0 Windows 2K environment - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/5f02c483545e5973 * Communication between applets in seperate browswer windows? - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/4095d0c98d1e8cdf * Help: What is a .do web page extension? - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/399bdb61556ff2ca * Help ....API's - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/43884fd5c0b83a71 * performance of double checked locking - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6881393065d8371a * Threadsafe Timers? - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/84b90615248a59bc * Java Game Development SDK (Shadowed Horizons) - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e39c25c54f64d4c2 * Classes in jar can't load - why? - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/dc2f55bd4b5e0165 * SimpleDateFormat Help - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/91f141dd9dce11c0 * LDAP GMT date/time conversion - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7fab3851d3073e8d * servlet getRequestDispatcher issue - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/9deaca3dc5c2146e ============================================================================== TOPIC: Struts Server-Side Form Validation http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e8d7503f3780d747 ============================================================================== == 1 of 4 == Date: Thurs, Dec 16 2004 8:24 am From: "timmac" In my struts-config.xml file, I have: <plug-in className="org.apache.struts.validator.ValidatorPlugIn"> <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/> <set-property property="stopOnFirstError" value="true" /> </plug-in> And, in my validation.xml file, I have: <form-validation> <formset> <form name="registerFormBean"> <field property="firstName" depends="required"> <arg0 key="registerFormBean.firstName" /> </field> <field property="lastName" depends="required"> <arg0 key="registerFormBean.lastName" /> </field> <field property="age" depends="required,integer"> <arg0 key="registerFormBean.age"/> </field> </form> </formset> </form-validation> What gets me is that client-side validation seems to work fine, suggesting (in my naivety) that the definitions are probably all correct. Thanks so much for any further assistance you can offer! -Tim MacDonald == 2 of 4 == Date: Thurs, Dec 16 2004 8:24 am From: "timmac" In my struts-config.xml file, I have: <plug-in className="org.apache.struts.validator.ValidatorPlugIn"> <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/> <set-property property="stopOnFirstError" value="true" /> </plug-in> And, in my validation.xml file, I have: <form-validation> <formset> <form name="registerFormBean"> <field property="firstName" depends="required"> <arg0 key="registerFormBean.firstName" /> </field> <field property="lastName" depends="required"> <arg0 key="registerFormBean.lastName" /> </field> <field property="age" depends="required,integer"> <arg0 key="registerFormBean.age"/> </field> </form> </formset> </form-validation> What gets me is that client-side validation seems to work fine, suggesting (in my naivety) that the definitions are probably all correct. Thanks so much for any further assistance you can offer! -Tim MacDonald == 3 of 4 == Date: Thurs, Dec 16 2004 9:03 am From: "timmac" In my struts-config.xml file, I have: <plug-in className="org.apache.struts.validator.ValidatorPlugIn"> <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/> <set-property property="stopOnFirstError" value="true" /> </plug-in> And, in my validation.xml file, I have: <form-validation> <formset> <form name="registerFormBean"> <field property="firstName" depends="required"> <arg0 key="registerFormBean.firstName" /> </field> <field property="lastName" depends="required"> <arg0 key="registerFormBean.lastName" /> </field> <field property="age" depends="required,integer"> <arg0 key="registerFormBean.age"/> </field> </form> </formset> </form-validation> What gets me is that client-side validation seems to work fine, suggesting (in my naivety) that the definitions are probably all correct. Thanks so much for any further assistance you can offer! -Tim MacDonald == 4 of 4 == Date: Thurs, Dec 16 2004 1:04 pm From: Sudsy timmac wrote: <snip> Two things: 1. Validation requires that your class extend one of the Validator classes, e.g. ValidatorForm. Those have an implementation of the validate method which will utilize the validations you specify (which look to be fine, BTW). 2. The input attribute of the action element in struts-config.xml should point to a page which will be displayed if validation fails. This is often the same as the page which submitted to the action in the first place. For more, I've written an article which discussed some of these concepts. You can find it here: <http://www.sudsy.net/technology/validation.html> ============================================================================== TOPIC: Need some help with Java application. http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f2f2f1701ec9cacd ============================================================================== == 1 of 1 == Date: Thurs, Dec 16 2004 8:24 am From: "vatsy" aint exactly paydirt but shud help.... The Care and Feeding of Runtime.exec http://developer.apple.com/technotes/tn/tn1168.html check if u can lay ur hands on sdk 1.5 for mac.................... ============================================================================== TOPIC: simple prog in javax.comm not running http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6e4091413a3cdbf3 ============================================================================== == 1 of 3 == Date: Thurs, Dec 16 2004 8:38 am From: "atishay" i wrote a simple prg as follows: -----8<-------- import java.io.*; import java.util.*; import javax.comm.*; public class SimpleList { static CommPortIdentifier portId; static Enumeration portList; SerialPort serialPort; public static void main(String[] args) { portList = CommPortIdentifier.getPortIdentifiers(); while (portList.hasMoreElements()) { portId = (CommPortIdentifier) portList.nextElement(); if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) { System.out.println("Port Name is "+portId.getName()); } } } } ------8<----------- PROBLEM IS that the program is compiling but when i run it i ger the followiing error Exception in thread "main" java.lang.NoClassDefFoundError: javax/comm/CommPortId entifier at SimpleList.main(SimpleList.java:13) how do i solve it? I have following settings JDK version : 1.4.2_03 comm.jar : C:\j2sdk1.4.2_03\jre\lib\ext\comm.jar javax.comm.properties: C:\j2sdk1.4.2_03\jre\lib\javax.comm.properties win32com.dll : C:\j2sdk1.4.2_03\jre\bin\win32com.dll OS: Windows Xp sp2 thanks -- :) Atishay Kumar == 2 of 3 == Date: Thurs, Dec 16 2004 9:53 am From: Knute Johnson atishay wrote: > i wrote a simple prg as follows: > -----8<-------- > > import java.io.*; > import java.util.*; > import javax.comm.*; > > public class SimpleList { > static CommPortIdentifier portId; > static Enumeration portList; > > > SerialPort serialPort; > > > public static void main(String[] args) { > portList = CommPortIdentifier.getPortIdentifiers(); > > while (portList.hasMoreElements()) { > portId = (CommPortIdentifier) portList.nextElement(); > if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) > { > System.out.println("Port Name is "+portId.getName()); > > } > } > } > } > > > ------8<----------- > > PROBLEM IS that the program is compiling but when i run it i ger the > followiing error > Exception in thread "main" java.lang.NoClassDefFoundError: > javax/comm/CommPortId > entifier at SimpleList.main(SimpleList.java:13) > > > how do i solve it? I have following settings > > JDK version : 1.4.2_03 > comm.jar : C:\j2sdk1.4.2_03\jre\lib\ext\comm.jar > javax.comm.properties: C:\j2sdk1.4.2_03\jre\lib\javax.comm.properties > win32com.dll : C:\j2sdk1.4.2_03\jre\bin\win32com.dll > OS: Windows Xp sp2 > > thanks To run programs rather than compile them you need to put the files in the JRE directories not the SDK/JRE directories. -- Knute Johnson email s/nospam/knute/ == 3 of 3 == Date: Thurs, Dec 16 2004 10:10 am From: "atishay" Thank a lot!!! it worked But may i know why ?? and what is the significance of 2 JREs. one in c:\prog...\java\jre and other <jdk>\jre thanks atishay ============================================================================== TOPIC: JSP EL and explicit error messages http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/65e5ee92bf562a84 ============================================================================== == 1 of 1 == Date: Thurs, Dec 16 2004 11:47 am From: "John C. Bollinger" massdriver wrote: > Hi, > > I sometimes mistype object and property names in JSP EL expressions, > and find that no error is generated. It just doesn't evaluate the > expression. > > For example, for an object named foo with a property of name, this > would throw an error: > > <%= foo.getNAme() %> > > where this won't: > > ${foo.nAme} > > Is there any way to make it produce explicit errors in a case like this? You're comparing apples and oranges. Scriptlets are included directly in Java code at translation time, and typos then cause the page compilation to fail. The container has no alternative but to signal an error, which it generally does with HTTP response code 500. EL expressions, on the other hand, are evaluated at runtime by an ExpressionEvaluator instance or by an Expression instance obtained from an ExpressionEvaluator. Inability of either of these objects to evaluate an expression should cause an exception to be thrown, but it is possible for the page implementation to catch it, which may be your problem. I don't see anything in the JSP 2.0 spec that says either way whether a page compiler may provide default handling for such exceptions inside the page -- though I think that would be odd -- but you may have done it yourself in scriptlet code. John Bollinger [EMAIL PROTECTED] ============================================================================== TOPIC: J2ee example in Jboss http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d283362ec4397f86 ============================================================================== == 1 of 2 == Date: Thurs, Dec 16 2004 4:50 pm From: Flex Il Wed, 15 Dec 2004 21:34:54 -0500, Sudsy ha scritto: > <CUT> > I'll purchase a spoon as soon as you remit project funding via > PayPal... ;-) It isn't a good idea :-) This is the code that it generates exception : try { queueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup("QueueConnectionFactory"); queue = (Queue) jndiContext.lookup(queueName); } catch (NamingException e) { System.out.println("JNDI API lookup failed: " + e.toString()); System.exit(1); } It's strange , I digit to run : java -cp .:/opt/jboss/client/jboss-j2ee.jar:/opt/jboss/client/jbossall-client.jar SimpleQueueSender MyQueue 3 And this is the error message : Queue name is MyQueue JNDI API lookup failed: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial does Someone have got an idea ? -- Ciao Flex == 2 of 2 == Date: Thurs, Dec 16 2004 12:53 pm From: Sudsy Flex wrote: > does Someone have got an idea ? You're in luck! Someone just returned one of my spoons. Here you go: Properties p = new Properties(); props.setProperty( "java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory" ); props.setProperty( "java.naming.provider.url", "127.0.0.1:1099" ); props.setProperty( "java.naming.factory.url.pkgs", "org.jboss.naming" ); Context ctx = new InitialContext( props ); queueConnectionFactory = (QueueConnectionFactory) ctx.lookup( "QueueConnectionFactory" ); ... Feeling better now? ============================================================================== TOPIC: Setting Java Virtual Memory http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/991635c2a770e75c ============================================================================== == 1 of 1 == Date: Thurs, Dec 16 2004 7:05 pm From: Daniel Sjöblom Chris Smith wrote: > <[EMAIL PROTECTED]> wrote: > >>You are probably instantiating too many objects. Review your code. >> >>A common cause of this is using the '+=' construct to concatenate >>strings. Every time this is used, a StringBuffer is instantiated. > > > Nope, the implicit StringBuffer instances used to implement the += > operator on Strings will never cause an OutOfMemoryError. A full > garbage collection is guaranteed to occur prior to OutOfMemoryError > being thrown, so only the memory that's really required will contribute > toward this problem. The implicit object from += will be garbage > collected before the error is thrown. This is not strictly true, but it may be that I'm misinterpreting what you are saying. It is very much possible for the JVM to throw an OutOfMemoryError when concatenating large Strings. Here is an example illustrating such behaviour, it will print "Smart is ok", but will crash with an out of memory error before printing out "Naive is ok", when run on the Sun JVM without any additional flags (you may possibly have to play around with the number of iterations to get it to work as intended). Warning: running this may take a moderately long time. public class StringConcatenation { public static void main(String[] args) { final int ITERATIONS = 80; smarterConcat("", ITERATIONS); System.out.println("Smart is ok"); naiveConcat("", ITERATIONS); System.out.println("Naive is ok"); } public static String naiveConcat(String str, int iterations) { String str2 = new String(new char[100000]); for (int i = 0; i < iterations; i++) str += str2; return str; } public static String smarterConcat(String str, int iterations) { StringBuffer sb = new StringBuffer(str); String str2 = new String(new char[100000]); for (int i = 0; i < iterations; i++) sb.append(str2); return sb.toString(); } } -- Daniel Sjöblom Remove _NOSPAM to reply by mail ============================================================================== TOPIC: How to add Java .properties files to Apache Tomcat 4.0 Windows 2K environment http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/5f02c483545e5973 ============================================================================== == 1 of 1 == Date: Thurs, Dec 16 2004 9:11 am From: "milesd" Hi, I have a number of Java "???.???.??.???.properties" files which I would like Apache Tomcat 4.0 to "pick up" in it's environment. I have a JSP page which has the following exception: ---- no.fast.ds.content.ContentManagerFactoryException: Failed to instantiate class no.fast.ds.content.corba.ContentManagerFactory: java.lang.reflect.InvocationTargetException ---- I am fairly sure that the "not picking up of properties files" are causing this (unless someone know different). I have tried copying the properties files to a number of directories (including Apache Tomcat 4.0\conf\ntiis, and Apache Tomcat 4.0\webapps\webdav\WEB-INF\classes) - but with no success :( I have been unable to locate httpd.conf in the Windows Tomcat install (I have specified properties here when using Apache). Can someone provide me with some tips on how to resolve this issue. :) thanks Miles. ============================================================================== TOPIC: Communication between applets in seperate browswer windows? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/4095d0c98d1e8cdf ============================================================================== == 1 of 2 == Date: Thurs, Dec 16 2004 5:12 pm From: Andrew Thompson On Thu, 16 Dec 2004 15:30:38 GMT, Richard Smol wrote: >> Sockets would be one good way to allow the applets to communicate, >> though I suspect you are doing something wrong when you attempt >> to connect to the other applets. > > Even worse: I did find a way to do it. I do not know why that is 'even worse', but if you found a way to do it that works.. good. What was the problem/solution? >...HAHA! ? >..Now I can finally take over the world! ?? >...Or just get this application started :) ;-) > Thanks for your input... You're welcome. -- Andrew Thompson http://www.PhySci.org/codes/ Web & IT Help http://www.PhySci.org/ Open-source software suite http://www.1point1C.org/ Science & Technology http://www.LensEscapes.com/ Images that escape the mundane == 2 of 2 == Date: Thurs, Dec 16 2004 1:17 pm From: "John C. Bollinger" Richard Smol wrote: > I have this web-application where is one main applet, that opens > several browser windows and then has to be notified whenever something > changes in those windows (like, when they close down or reload after > submitting a value). > > Now, I was thinking for using an invisible applets that sends > lifetime-changes to the main applet... but very much to my dismay > inter-applet communication doesn't work between seperate browser > windows.. at least not under Internet Explorer 6. It isn't supposed to work. In fact, it is specifically supposed to NOT work. In principal, applets should be able to communicate with each other *within the same document*, but even that (accomplished with use of the applet's AppletContext to find the other applet instances) can be flaky. Documents displayed in different windows, even if they have the same source, are different documents. John Bollinger [EMAIL PROTECTED] ============================================================================== TOPIC: Help: What is a .do web page extension? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/399bdb61556ff2ca ============================================================================== == 1 of 1 == Date: Thurs, Dec 16 2004 5:14 pm From: Juha Laiho [EMAIL PROTECTED] said: >Since I am new to Java web development, I was stummped when one of my >clients asked me if I could do some web page maintenance to a ".do" web >page file. He tells me that this page was written in Java. If I recall correctly, at least the Struts MVC framework utilizes URL's ending with ".do". See http://struts.apache.org/ . -- Wolf a.k.a. Juha Laiho Espoo, Finland (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++ "...cancel my subscription to the resurrection!" (Jim Morrison) ============================================================================== TOPIC: Help ....API's http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/43884fd5c0b83a71 ============================================================================== == 1 of 1 == Date: Thurs, Dec 16 2004 5:56 pm From: stevek Thanks for the help. Michael Borgwardt wrote: > stevek wrote: > >> Looking at a program that has the following. >> import java.io.*; >> import javax.servlet.*; >> import javax.servlet.http.*; >> >> java.io is ok but I can not find info on javax.servlet.*. Any help? > > > javax.servlet is part of J2EE, not J2SE. Any Server that deals with > Servlets > and JSPs will come with a JAR file that contains those classes. It's often > calles servlet.jar. ============================================================================== TOPIC: performance of double checked locking http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6881393065d8371a ============================================================================== == 1 of 2 == Date: Thurs, Dec 16 2004 1:05 pm From: "John C. Bollinger" Gerald Thaler wrote: > Hello > > The double checked locking idiom (thread safe singelton pattern) now works > correct under the current memory model: Where "works correct" means "is thread safe". > public class MySingleton { > > private static volatile MySingleton instance; > > public static MySingleton getInstance() { > if (instance == null) { > synchronized (MySingleton.class) { > if (instance == null) { > instance = new MySingleton(); > } > } > } > return instance; > } > } > > Nevertheless the Java experts still discourage its use, claiming that there > would be no signifcant performance advantage over simply synchronizing the > whole getInstance() method, as volatile variable accesses are similar to > (half) a synchronization. > > For example see: > http://www-106.ibm.com/developerworks/library/j-jtp03304/?ca=dnt-513 [Brian > Goetz] > > But is this really true? IMHO the volatile read in the common code path > should be much more efficient than a monitor enter can be in any reasonable > JVM implementation. All it has usually to do is to cross a read barrier > before the read of the variable 'instance'. This affects only one processor > and will cost very few cycles if any. A monitor enter in contrast would > require a bus lock during a read-modify-write operation. This would stall > every processor in the system. So my feeling is, that a monitor enter should > be much more expensive than a volatile read. Read the reference material you pointed to yourself. When a thread performs a read on a volatile variable, it must (logically) discard its local memory and reload from main memory, very much like on a monitor enter. This is required by the new semantics of volatile that prevent accesses to nonvolatile variables from being reordered with accesses to volatile ones in the program order. It may be that a JVM can provide very efficient implementation of this requirement, but in that case it should be able to provide a similarly efficient implementation of monitor entry. Now there _is_ the point that a read (only) of a volatile variable is not paired with any equivalent of a monitor exit, which does make it somewhat lighter-weight than synchronization (and rather heavier-weight than it used to be). That probably isn't relevant to the double-checked locking situation, however: if the whole getInstance() method were synchronized then an optimizer could observe that no writes occur within the synchronized block (after the first time) and that therefore no actions need be performed on memory at monitor exit. Thus, synchronizing the whole getInstance() method can be very nearly as fast as double-checked locking of access to a volatile variable. > The linked site above gives the following advice: > > "Instead of double-checked locking, use the Initialize-on-demand Holder > Class idiom, which provides lazy initialization, is thread-safe, and is > faster and less confusing than double-checked locking." > > I don't agree. First, the Initialize-on-demand Holder Class idiom doesn't > garantee that the Singleton is not constructed until its first use. JVMs > have great freedom here. Second, if it does indeed lazy initialization, it > can't be any faster than DCL, because it too has to cross at least one read > barrier internally. 1) A high-performance JVM will perform lazy initialization if it improves performance. Other JVMs are not relevant, nor is lazy initialization if it doesn't improve performance. 2) Initialize-on-demand can be significantly faster than DCL on a volatile variable, because after initialization (of the _final_ variable) no read barrier need be crossed to access it. I really fail to understand the fascination with DCL. It used to not provide the intended thread safety in Java, but people kept trying to "fix" it. Under the new memory model DCL can be made to work, but at a probable performance cost relative to some of the same simpler alternatives that have always worked. It is inherent in the design of DCL that it must place some kind of synchronization demands on every access to the protected variable. There is no way to avoid it within that scheme while still providing thread safety. Consider, for instance, that the additional overhead required for volatile access under the _old_ JMM *wasn't enough* to ensure thread safety for DCL. So GET OVER IT! Do not use DCL in Java. The plain flavor is broken, and on older VMs the volatile-based flavor is both more expensive than the plain one *and* broken. On VMs where the volatile-based version is thread-safe, it is comparatively expensive relative to alternatives. John Bollinger [EMAIL PROTECTED] == 2 of 2 == Date: Thurs, Dec 16 2004 8:07 pm From: "Gerald Thaler" > Read the reference material you pointed to yourself. When a thread > performs a read on a volatile variable, it must (logically) discard its > local memory and reload from main memory, very much like on a monitor > enter. This is required by the new semantics of volatile that prevent > accesses to nonvolatile variables from being reordered with accesses to > volatile ones in the program order. It may be that a JVM can provide very > efficient implementation of this requirement, but in that case it should > be able to provide a similarly efficient implementation of monitor entry. This is just not true. Monitor entry does more: It provides mutual exclusion. It's impossible to implement this without atomic read-modify-write instrucions at the machine level. They must lock the bus and so effekt _every_ processor in the system. Look at the x86 for example: Monitor entry must execute an instruction like LOCK XADD. This is painfully slow. For volatile read it suffices that the Compiler/VM doesn't reorder instructions. This may prevent some optimizations that would otherwise apply. But other than that there are _no_ performance penalties in the common code path at all. On x86 volatile reads are way faster than monitor entry. On other architectures the cost may be somewhat higher. >> The linked site above gives the following advice: >> >> "Instead of double-checked locking, use the Initialize-on-demand Holder >> Class idiom, which provides lazy initialization, is thread-safe, and is >> faster and less confusing than double-checked locking." >> >> I don't agree. First, the Initialize-on-demand Holder Class idiom doesn't >> garantee that the Singleton is not constructed until its first use. JVMs >> have great freedom here. Second, if it does indeed lazy initialization, >> it can't be any faster than DCL, because it too has to cross at least one >> read barrier internally. > > 1) A high-performance JVM will perform lazy initialization if it improves > performance. Other JVMs are not relevant, nor is lazy initialization if > it doesn't improve performance. I doubt that. Many VMs will load a class as soon as the control flow enters a method, that *could* access it: public void method() { if (christmasIsToday()) { BigFatPresent present = BigFatPresent.getInstance(); // Do something with is } } The VM cannot decide wether my static initialization is expensive or not. > 2) Initialize-on-demand can be significantly faster than DCL on a volatile > variable, because after initialization (of the _final_ variable) no read > barrier need be crossed to access it. There must be a read barrier somewhere. > I really fail to understand the fascination with DCL. It used to not > provide the intended thread safety in Java, but people kept trying to > "fix" it. > Under the new memory model DCL can be made to work, but at a probable > performance cost relative to some of the same simpler alternatives that > have always worked. > It is inherent in the design of DCL that it must place some kind of > synchronization demands on every access to the protected variable. There > is no way to avoid it within that scheme while still providing thread > safety. Consider, for instance, that the additional overhead required for > volatile access under the _old_ JMM *wasn't enough* to ensure thread > safety for DCL. > > So GET OVER IT! Do not use DCL in Java. The plain flavor is broken, and > on older VMs the volatile-based flavor is both more expensive than the > plain one *and* broken. On VMs where the volatile-based version is > thread-safe, it is comparatively expensive relative to alternatives. "volatile" is a valid and useful means of thread-communication under the new memory model and DCL isn't broken anymore. But i agree, that in 99.9% of all situations it's simply not worth to optimize away the synchronization. ============================================================================== TOPIC: Threadsafe Timers? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/84b90615248a59bc ============================================================================== == 1 of 1 == Date: Thurs, Dec 16 2004 1:21 pm From: "John C. Bollinger" [EMAIL PROTECTED] wrote: > I have recently begun the joys of ensuring that all of my GUI/Swing > code is thread safe by adding invokeLater() and invokeAndWait() methods > everywhere. As far as I can tell, all Swing classes are assumed to NOT > be thread safe. Does this include javax.swing.Timer? Specifically, I > use Timers all over the place for regularly scheduled tasks and when I > turn them on or off, or restart() them, do these also need to be > enclosed in invokeLater() and invokeAndWait() methods? Is it safe to > assume that the event handlers for Timers execute on the event > dispatching thread so that anything within these tasks is safe without > the extra protection? In case it matters my target JVM is the 1.3.1_07 > JRE from Sun. Thanks for any help! From the API docs for javax.swing.Timer: "Although all Timers perform their waiting using a single, shared thread (created by the first Timer object that executes), the action event handlers for Timers execute on another thread -- the event-dispatching thread. This means that the action handlers for Timers can safely perform operations on Swing components. However, it also means that the handlers must execute quickly to keep the GUI responsive." John Bollinger [EMAIL PROTECTED] ============================================================================== TOPIC: Java Game Development SDK (Shadowed Horizons) http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e39c25c54f64d4c2 ============================================================================== == 1 of 1 == Date: Thurs, Dec 16 2004 10:28 am From: "Greg Brown" Hello, I have just released my first Java version of my Gaming SDK on Sourceforge, I am actively seeking assistance with this project, and apologize for the mass USENET posting, but please check out the link if you are interested, and feel free to contact me, or post your thoughts in response to this. http://sourceforge.net/projects/shadowed ============================================================================== TOPIC: Classes in jar can't load - why? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/dc2f55bd4b5e0165 ============================================================================== == 1 of 1 == Date: Thurs, Dec 16 2004 6:54 pm From: Tilman Bohn In message <[EMAIL PROTECTED]>, Jack Andersson wrote on Thu, 16 Dec 2004 10:08:49 +0100: [...] > Believe me, I tried using the command line version of jar. What > happened? The jar crashes and spits out 7589342573489 strange > characters including the bell one, which made my computer sound like a > fire alarm. Which just means you didn't specify the f option so it created the archive and wrote it to stdout -- your terminal. It didn't crash at all. It did exactly what you told it to. > That in turn made my collegues rather upset. I won't use the command > line jar again unless I'm completely alone. A much better approach would be to try and understand why it printed to stdout and how to make it write the output somewhere else. Cheers, Tilman -- `Boy, life takes a long time to live...' -- Steven Wright ============================================================================== TOPIC: SimpleDateFormat Help http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/91f141dd9dce11c0 ============================================================================== == 1 of 1 == Date: Thurs, Dec 16 2004 11:12 am From: [EMAIL PROTECTED] (Seb) Hello, I have an old database which had multiple dates stored in it. Unfortunately, there were no fixed format for these dates and I now have to standardize everything. In the past, I used to create a Date object using the Date(String) constructor in order to parse the string containing the date, since this constructor could recognize a date in (almost) any format. Unfortunately, this constructor is now deprecated and I want to use a non-deprecated method. I tried to use the suggested replacement to this constructor, which is the DateFormat.parse(String) method, but this method requires that we specify the date format before parsing the date. As I mentioned previously, I don't know the format of the field and don't really know what to use anymore. Any help would be more than welcome. thanks in advance. ============================================================================== TOPIC: LDAP GMT date/time conversion http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7fab3851d3073e8d ============================================================================== == 1 of 1 == Date: Thurs, Dec 16 2004 11:16 am From: [EMAIL PROTECTED] I have an LDAP date/time entry that I need to convert to a readable format for display. The format of the date in LDAP is supposed to be GMT. An actual date entry in LDAP is: 20041216174159Z . The only field that is off is the hour field ('17' when the actual hour in local time was 09 (a.m.) ) - all of the other fields are correct. I've looked through Novell and Suns sites for a solution to this but have come up empty handed. Any pointers would be appreciated. ============================================================================== TOPIC: servlet getRequestDispatcher issue http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/9deaca3dc5c2146e ============================================================================== == 1 of 1 == Date: Thurs, Dec 16 2004 11:17 am From: "psrikant" Here is what i feel is giving u the error. when u r comparing aReturn == true, aReturn should have some value that has been returned by the authenticate method. You must do aReturn = authenticate(ausername, apassword); This should solve your NullPointerException. hope it helps. Let me know vic wrote: > Hello All, > > I am having this issue with my Servlet, cant seem to understand. I > have the snippet of the servlet below whihch forwards the request to a > jsp based on what the method condition returns. The servlet however > does forward to the appropriate jsp but then gives a NUll pointer > exception. > > Here is the servlet snippet > > public void doPost (HttpServletRequest request, HttpServletResponse > response) throws ServletException, java.io.IOException { > > > ausername = request.getParameter("ausername"); > apassword = request.getParameter("apassword"); > > try { > > authenticate(ausername, apassword); //returns true if user is > valid and else false > > if(aReturn == true) { > this.getServletContext().getRequestDispatcher("/gototrue.jsp").forward(request, > response); > > } > else { > this.getServletContext().getRequestDispatcher("/gotofalse.jsp").forward(request, > response); > } > } > catch (ServletException se) { > } > > Here is the error log i get: > > <Error> <HTTP> <[WebAppServletContext(1531469,myapp,/ > myapp)] Servlet failed with Exception > java.lang.NullPointerException > at csf.webcntrl.HTTPRMIAdapter.doPost(HTTPRMIAdapter.java:71) > at javax.servlet.http.HttpServlet.service(HttpServlet.java:760) > at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) > at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm > pl.java:262) > at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm > pl.java:198) > at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe > rvletContext.java:2637) > at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm > pl.java:2359) > at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139) > at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120) > > Am i missing something, session , ServletContext() or something on > those lines. > > Any help is appreciated ============================================================================== You received this message because you are subscribed to the Google Groups "comp.lang.java.programmer" group. To post to this group, send email to [EMAIL PROTECTED] or visit http://groups-beta.google.com/group/comp.lang.java.programmer To unsubscribe from this group, send email to [EMAIL PROTECTED] To change the way you get mail from this group, visit: http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe To report abuse, send email explaining the problem to [EMAIL PROTECTED] ============================================================================== Google Groups: http://groups-beta.google.com
