Thread and mutable params
java, multithreading, thread-safety
Solution
Given I don't have any class variable, is it thread safe if I call objectA.foo(new Customer()) from different threads?
Of course it is. Your `foo()` method doesn't change any state of the `A` object (since it doesn't have any) and the object you pass, `new Customer()`, as an argument to the method is not available to any other thread.
What if I change foo to static and call A.foo(new Customer()) from different threads? is it still thread safe?
As long as you don't have any mutable `static` state, you're still good.
Problem
I'm new to Java, so pls excuse if answer to below simple case is obvious. ``` class A{ public void foo(Customer cust){ cust.setName(cust.getFirstName() + " " + cust.getLastName()); cust.setAddress(new Address("Rome")); } } ``` I've a Singleton object (`objectA`) created for class `A`. Given I don't have any class variable, is it thread safe if I call `objectA.foo(new Customer())` from different threads? What if I change foo to static and call `A.foo(new Customer())` from different threads? is it still thread safe?