Avatar billede fredand Forsker
18. oktober 2010 - 21:29 Der er 3 kommentarer og
1 løsning

Could this be a no thread safe problem?

Hello!

We are running some prestanda-test right now.
We try to stress our application.

We saw some "strange" errors due.

ArrayOutOfBoundsException.

In a method looking pretty like this, (home right now, code is at work)

public static String formatStringToDate(String input)
{
  ... some code...
  return YYYYMMDD.format(); //Exception at this line
}

YYYYMMDD is if not wrong SimpleDateFormat.

How ever we got some, perhaps 4, ArrayOutOfBoundsException 46, ArrayOutOfBoundsException -16 etc.

...after 5000 requests through JBossWS down to this DateUtil class.

All the time the method got the parameter set to the same value, like "2010-10-08".

Since we just got a few errors and the calls got the same parameters, I started to think that this problem might depend on thread safety, or I'm I wrong?

Is it possible that several threads access this method at the same time and screw up each others calls?

Best regards
Fredrik
Avatar billede madiedk Nybegynder
18. oktober 2010 - 22:11 #1
try make the method synchronized and see if the problem still occurs
Avatar billede fredand Forsker
19. oktober 2010 - 11:32 #3
Hello Guys!

Thanks for your replies!

Yes the problem must be that ... snippet from javadoc:
Date formats are not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally.

Please give svar so I can reward you guys!

Thanks alot!
Fredrik
Avatar billede madiedk Nybegynder
19. oktober 2010 - 23:33 #4
you are welcome
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester