-1
public void synchronized method1(Class_Instance_Variables instanceVar, int classprimitive)
public void method2(Class_Instance_Variables instanceVar, int classprimitive)

When passing parameters to method does java creates fresh reference to the methods or does it use existing reference to pass to the methods ?

Thread-1 get the lock of synchronized method1 and pass "class instance variable" and class instance primitive variable. Thread-2 pass method2 pass same "class instance variable" and class instance primitive variable.

How the references work in this case ? Does it create a new reference for each passing?

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
Kasun
  • 561
  • 11
  • 22
  • 1
    Nope. This is not a duplicate. The question is relating to the references is it creating a new one or use existing reference. – Kasun Mar 20 '14 at 21:42
  • 1
    How would you tell the difference between a fresh reference and the same reference? Why would it matter? – Alan Stokes Mar 20 '14 at 21:43
  • 1
    Read the question and answers. Unless you're not formulating your question right, this is an exact duplicate. The fact that threads and `synchronized` are involved is irrelevant. – Sotirios Delimanolis Mar 20 '14 at 21:46
  • In addition to the linked question, see also the official tutorial on [passing arguments to methods](http://docs.oracle.com/javase/tutorial/java/javaOO/arguments.html). Whether or not a method is `synchronized` has no effect on how parameters are passed. – Jason C Mar 20 '14 at 21:54

1 Answers1

0

A reference is just an address value (modulo the indirection inherent in heap management). Talking about the difference between two references is like talking about the difference between two integers -- outside of which memory location they occupy, if they're the same value there is NO difference between them.

You may be confused because you're assuming Java heap management is reference-counted, in which case references are independent objects. It isn't; Java uses mark/sweep GC, and a reference is just a pointer.

There are no "new references". There are just references. Threads or not.

keshlam
  • 7,931
  • 2
  • 19
  • 33