synchronizing primitive parms
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Woodrow_Kaczynski
Posted On:   Wednesday, March 13, 2002 12:36 PM

Are the primitive parms threadsafe?


Can I reference them directly safely within a synchronized method or do I need to create another local variable for referencing?

Re: synchronizing primitive parms

Posted By:   Marian_Olteanu  
Posted On:   Tuesday, March 19, 2002 02:22 AM

If you understand by primitive params, parameters of type int, bool, char, byte, etc. of a method, yes, they are thread safe, for a very simple reason: in Java, all parameters are passed by value, not by reference (when you pass an int, the int is copyed on stack, when you think you pass, for example, a Vector, which is an object, you really pass a reference to it, a reference passed by copying it on stack). So, the method has exclusive access to its primitive params, so even if you don't sync. it, it is thread safe to modify them and do whatever you want to do with them.
About | Sitemap | Contact