Re: Re[4]: java.util.Date
Apologies if I'm misinterpreting, but I think Antoni's concern is that the SimpleDateFormat's parse and format methods are not thread-safe. The creation of the converters and their registration can obviously be accomplished in a thread-safe manner, but if multiple threads call into parse and/or format at the same time, this will cause a problem. If that's not what Antoni was saying...it's still a problem ;-). Shouldn't you code a Converter's convert method with the same approach to thread-safety as an Action's execute/perform method? If your Converter maintains a SimpleDateFormat instance field that it uses to either format or parse, it's not thread safe. Quoting Rick Reumann [EMAIL PROTECTED]: On Wednesday, November 6, 2002, 4:05:45 PM, Antoni wrote: AR Hi, I don't speak english very very well, so this is a bit AR difficult for me to explain, but I'll try ;-) No problem. Most American's don't speak English very well (including myself I'm sure:) AR I have'nt looked at the beanutils Converter registration, do you have to AR register a class or an instance? It registers an instance one time in the static block at the top of the action: static { DateBeanUtilsConverter dateConverter = new DateBeanUtilsConverter(); dateConverter.setFormatPattern( MMdd ); StringBeanUtilsConverterDate myStringConverter = new StringBeanUtilsConverterDate(); myStringConverter.setFormatPattern( MMdd ); ConvertUtils.register( dateConverter, java.util.Date.class ); ConvertUtils.register( myStringConverter, String.class ); } AR The problem here is that if there is only one instance of your class, and AR setFormatPattern is only called once, then if there are two request that AR require the use of your class a the same time, served by different threads, AR the parse method in your instance of SimpleDateFormat might be called AR concurrently, so (as it isn't thread save) it might fail. I'm not sure how this would happen as Eddie have both pointed out that the static block will only get called one time regardless of how many instances are created (at least on a single JVM I'm pretty sure that's the case). (On top of that I'm pretty sure on one JVM user's all share one servlet instance unless you maybe use that SingleThreadModel which I think hands them out from a pool. Moot point though I think if I do the stuff in the static block. But I could be wrong). -- Rick mailto:maillist;reumann.net -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org -- Kris Schneider mailto:kris;dotech.com D.O.Tech http://www.dotech.com/ -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org
Re: Re[4]: java.util.Date
A Dimecres 06 Novembre 2002 22:19, Rick Reumann va escriure: On Wednesday, November 6, 2002, 4:05:45 PM, Antoni wrote: AR Hi, I don't speak english very very well, so this is a bit AR difficult for me to explain, but I'll try ;-) No problem. Most American's don't speak English very well (including myself I'm sure:) :) AR I have'nt looked at the beanutils Converter registration, do you have to AR register a class or an instance? It registers an instance one time in the static block at the top of the action: static { DateBeanUtilsConverter dateConverter = new DateBeanUtilsConverter(); dateConverter.setFormatPattern( MMdd ); StringBeanUtilsConverterDate myStringConverter = new StringBeanUtilsConverterDate(); myStringConverter.setFormatPattern( MMdd ); ConvertUtils.register( dateConverter, java.util.Date.class ); ConvertUtils.register( myStringConverter, String.class ); } AR The problem here is that if there is only one instance of your class, and AR setFormatPattern is only called once, then if there are two request that AR require the use of your class a the same time, served by different threads, AR the parse method in your instance of SimpleDateFormat might be called AR concurrently, so (as it isn't thread save) it might fail. I'm not sure how this would happen as Eddie have both pointed out that the static block will only get called one time regardless of how many instances are created (at least on a single JVM I'm pretty sure that's the case). (On top of that I'm pretty sure on one JVM user's all share one servlet instance unless you maybe use that SingleThreadModel which I think hands them out from a pool. Moot point though I think if I do the stuff in the static block. But I could be wrong). The problem is not in the static code, the problem is reusing the same instance of SimpleDateFormat Your initial aproach is fine. But let see what could happen if you move the SimpleDateFormat creation to the setFormatPattern method: - when the class loader loads your Action the static bloc is executed: 1- an instance of your converter is created 2- the setFormatPattern is called and an instance off SimpleDateFormat is created. 3- the converter instance is registered - there are 2 request at the same time that target an action that uses BeanUtils.copyProperties with a bean that has a Date. - the 2 request are served by to differents threads A and B 4- thread A begins the execution of the Action.execute, 5- thread A begins the execution of BeanUtils.copyProperties 6- thread A begins the execution of DateBeanUtilsConverter.convert 7- thread A begins the execution of SimpleDateFormat.parse 8- thread A is stopped and thread B begins the execution 9- thread B begins the execution of the Action.execute, 10- thread B begins the execution of BeanUtils.copyProperties 11- thread B begins the execution of DateBeanUtilsConverter.convert 12- thread B begins the execution of SimpleDateFormat.parse 13- thread B is stopped and thread A begins the execution 14 - thread A continues the execution of SimpleDateFormat.parse , but a internal attribute of SimpleDateFormat where modified and it fails. The problem is that during execution of SimpleDateFormat.parse some private fields of SimpleDateFormat are modified. You can take a look at http://developer.java.sun.com/developer/bugParade/bugs/4228335.html for details on the format classes not being thread-save issue -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org
Re: Re[4]: java.util.Date
Hi, A Dimecres 06 Novembre 2002 22:31, Kris Schneider va escriure: Apologies if I'm misinterpreting, but I think Antoni's concern is that the SimpleDateFormat's parse and format methods are not thread-safe. The creation of the converters and their registration can obviously be accomplished in a thread-safe manner, but if multiple threads call into parse and/or format at the same time, this will cause a problem. If that's not what Antoni was saying...it's still a problem ;-). Shouldn't you code a Converter's convert method with the same approach to thread-safety as an Action's execute/perform method? If your Converter maintains a SimpleDateFormat instance field that it uses to either format or parse, it's not thread safe. That's exactly what I was trying to say! Thanks for the clarification Quoting Rick Reumann [EMAIL PROTECTED]: On Wednesday, November 6, 2002, 4:05:45 PM, Antoni wrote: AR Hi, I don't speak english very very well, so this is a bit AR difficult for me to explain, but I'll try ;-) No problem. Most American's don't speak English very well (including myself I'm sure:) AR I have'nt looked at the beanutils Converter registration, do you have to AR register a class or an instance? It registers an instance one time in the static block at the top of the action: static { DateBeanUtilsConverter dateConverter = new DateBeanUtilsConverter(); dateConverter.setFormatPattern( MMdd ); StringBeanUtilsConverterDate myStringConverter = new StringBeanUtilsConverterDate(); myStringConverter.setFormatPattern( MMdd ); ConvertUtils.register( dateConverter, java.util.Date.class ); ConvertUtils.register( myStringConverter, String.class ); } AR The problem here is that if there is only one instance of your class, and AR setFormatPattern is only called once, then if there are two request that AR require the use of your class a the same time, served by different threads, AR the parse method in your instance of SimpleDateFormat might be called AR concurrently, so (as it isn't thread save) it might fail. I'm not sure how this would happen as Eddie have both pointed out that the static block will only get called one time regardless of how many instances are created (at least on a single JVM I'm pretty sure that's the case). (On top of that I'm pretty sure on one JVM user's all share one servlet instance unless you maybe use that SingleThreadModel which I think hands them out from a pool. Moot point though I think if I do the stuff in the static block. But I could be wrong). -- Rick mailto:maillist;reumann.net -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org