Hello, Arrays r objects in Java, so does this mean they too have locks - what i mean is - as we synchronize on an object can a array too be synchronized. sample:: public class Test{ public static void main(String[] args){ synchronized(args){ // some code } }//main - - }//class
hi Mona, Any object is allowed in the synchronized block except 1) Primitives 2) Local variable that is an object reference And yes array also have LOCKS. Hope this helps.
- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. <br />- What truth? <br />- That there is no spoon!!!
Mona Gadkari
Ranch Hand
Joined: Jul 28, 2003
Posts: 64
posted
0
Originally posted by Vicken Karaoghlanian: hi Mona, Any object is allowed in the synchronized block except 1) Primitives 2) Local variable that is an object reference And yes array also have LOCKS. Hope this helps.
Hi Vicken would you be kind to explain me why did you write Any object is allowed in the synchronized block except 1) Primitives public class Test { protected int j = 10; void changeValue(int _i){ synchronized ( j ) { j = _i; } } }
It doesn't work !
Am I misunderstood something?
Aleksandar Stojanovic
Aleksandar Stojanovic
Greenhorn
Joined: Sep 08, 2003
Posts: 26
posted
0
Sorry Vicken now I've seen word EXCEPT, sorry again and thanks for explanation :roll:
You could not ask for a clearer example of a common cause of missing questions than the above messages. You MUST read the question carefully - it may ask "which of the following is illegal" or "which of the following is legal" There is plenty of time, don't rush through the question text. Bill
Originally posted by Vicken Karaoghlanian: hi Mona, Any object is allowed in the synchronized block except 1) Primitives 2) Local variable that is an object reference And yes array also have LOCKS. Hope this helps.
Objects referenced by local variables are perfectly valid for synchronized blocks.