This is a question about a multi-threaded program.
Imagine we have a singleton class and we call an instance of it from 2 different threads.
Both threads will now have a reference to the same object in memory.
If the singleton class has a mehod which isn't synchronized and it accepts 2 numbers and just adds them.
If we call this method from Thread 1 and pass in 2 numbers and also call it from thread 2 and pass in 2 different numbers. This method doesn't use any class variables and only works on the parameters passed in.
Will the 2 calls to this method always operate independently of each other? Or would there ever be a chance where the 2 numbers passed in from thread 1 and thread 2 could get confused and add the first parameter from thread 1 to the second parameter from thread 2?
Originally posted by d jones: Hi, If the singleton class has a mehod which isn't synchronized and it accepts 2 numbers and just adds them.
If we call this method from Thread 1 and pass in 2 numbers and also call it from thread 2 and pass in 2 different numbers. This method doesn't use any class variables and only works on the parameters passed in.
Will the 2 calls to this method always operate independently of each other? Or would there ever be a chance where the 2 numbers passed in from thread 1 and thread 2 could get confused and add the first parameter from thread 1 to the second parameter from thread 2?
In the condition that you described, the two threads will operate independently of each other.