SimpleDateFormat thread problems?

Vladimir Leven vladimirl@wrx-ca.com
Mon May 10 18:19:00 GMT 2004


I did try putting "synchronize" keyword around getStats() method, but 
this did not solve the problem of the main scheduler thread hanging. 
Also, it seems to me that synchronization should not be required in the 
first place, since all I am doing is creating a Date from a long (which 
is updated by another thread, but presumably this.time = 
System.currentTimeMillis is atomic?) and then using SimpleDateFormat to 
print it.
Related question: Is there a way to dump the stack trace for a given 
thread? I can only seem to look at the stack trace for the currently 
running thread.
As for the patch, how do I apply it? Do I have to recompile all of GCC?
Thanks,
Vlad
Bryce McKinlay wrote:
> I suspect part of the problem is possibly broken/slow stack trace code 
> trying to call external programs to do a calling-classloader check.
>> Could you try this patch? It should fix the performance bug, but it 
> seems strange that it would cause your thread to hang. Particularly if 
> the problem only occurs in a threaded environment, it may be that 
> there are thread race/synchronization problems with your code. Make 
> sure you are synchronizing your threads correctly.
>> Bryce
>>> Vladimir Leven wrote:
>>> This is a bit vague, but maybe someone on this list will have some 
>> insights...
>>>> I have some simple Java code that runs in two threads. One thread 
>> runs a command line interface. Another thread runs a job scheduler. 
>> The job scheduler has a method that returns some stats as a string 
>> (e.g. scheduler start time, number of jobs processed so far, etc...). 
>> From the command line thread, I can ask for these stats. It seems 
>> that after asking for stats a few times, the job scheduler thread 
>> hangs, i.e. every time I ask for the stats, I get the same result. If 
>> I remove the SimpleDateFormat code that prints the date information 
>> in a human-readable way, this problem seems to go away. The stats 
>> command also runs noticeably faster.
>>>> Thanks for any help...
>>>>>------------------------------------------------------------------------
>>Index: java/util/Calendar.java
>===================================================================
>RCS file: /cvs/gcc/gcc/libjava/java/util/Calendar.java,v
>retrieving revision 1.19
>diff -u -r1.19 Calendar.java
>--- java/util/Calendar.java	7 May 2004 04:18:19 -0000	1.19
>+++ java/util/Calendar.java	10 May 2004 17:42:17 -0000
>@@ -376,7 +376,8 @@
> */
> private static ResourceBundle getBundle(Locale locale) 
> {
>- return ResourceBundle.getBundle(bundleName, locale);
>+ return ResourceBundle.getBundle(bundleName, locale,
>+ Calendar.class.getClassLoader());
> }
>> /**
>Index: java/text/DateFormat.java
>===================================================================
>RCS file: /cvs/gcc/gcc/libjava/java/text/DateFormat.java,v
>retrieving revision 1.13
>diff -u -r1.13 DateFormat.java
>--- java/text/DateFormat.java	20 Apr 2004 14:45:02 -0000	1.13
>+++ java/text/DateFormat.java	10 May 2004 17:42:17 -0000
>@@ -325,7 +325,7 @@
> try
> {
> 	res = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation",
>-				 loc);
>+				 loc, DateFormat.class.getClassLoader());
> }
> catch (MissingResourceException x)
> {
>Index: java/text/DateFormatSymbols.java
>===================================================================
>RCS file: /cvs/gcc/gcc/libjava/java/text/DateFormatSymbols.java,v
>retrieving revision 1.15
>diff -u -r1.15 DateFormatSymbols.java
>--- java/text/DateFormatSymbols.java	20 Apr 2004 14:45:04 -0000	1.15
>+++ java/text/DateFormatSymbols.java	10 May 2004 17:42:18 -0000
>@@ -98,7 +98,8 @@
> public DateFormatSymbols (Locale locale) throws MissingResourceException
> {
> ResourceBundle res
>- = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", locale);
>+ = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", locale,
>+ 				 getClass().getClassLoader());
>> ampms = res.getStringArray ("ampms");
> eras = res.getStringArray ("eras");
>>


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /