• Post Reply Bookmark Topic Watch Topic
  • New Topic

automatic synchronized

 
Stephan Staeheli
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there

I ask myself if method of an abstract base class is unique when called from different instances. Let me explain: I have abstract base class that has a method (not a static one, a simple instance method). Now I have a implementation class of this abstract base class that has a lot of instances. Now these instances all call this method from the base class, do I have to synchronize this method or gets the implementation class some kind of copy of the method when it inherits it and every instance has it's own copy?

I have the strange behavior that in this method I cast a string to a float value in a try-catch-block. Sometimes this method crashes with a NumberFormatException and in my log message I print out the input field of the method and this values differs from the one that jre writes out in the stackTrace!!!

Any help or hint is appreciated!

Regards,
Stephan
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The String which is being cast ... is it referenced by a local variable?
 
R Sawant
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can u explain it more clearly with some sample code.

Ramdas
 
Stephan Staeheli
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a part of the code:



Ok, now I think I just found the problem. The formatter is a static variable that is used by all instances of ImplClass. The DecimalFormatter is surly not synchronized, so this will be the problem.

Sometimes it just helps talking about a problem with somebody else. Thanks alot, it was a great pleasure!

Stephan
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!