Originally posted by Manfred Leonhardt:
Hi Rick,
I wouldn't really worry about it because that is the way the Math package was created. As long as you keep the methods short you should have no problems. Also, make sure you have a good reason to create a local copy of a variable. Since Java passes arguments by Value you can't change the original value anyway.
...
Regards,
Manfred.
In theory couldn't another object call this method and change the return value from what the original object calling the method would expect?
I'm starting to think though that some of my classes would be best as instance classes. Like for example I have a static method that takes a request object and from that object then goes ahead and populates a bean with all those request parameters. Now being that this method is static and shared across all who use the web application users could end up altering the bean's creation. In this case the question I think becomes is it better to synchronize a static method or make it an instance method. It seems best in this case to make an instance method since then all the users are waiting around to have access to a static method.
SCJP2. Please Indent your code using UBB Code
The intention must be provide each invocation with a set of unique values if those values could be modified by other invocations to the method.
The objects that compound the parameter could be modified if they are shared between different threads and they are mutable. Otherwise, given that each method invocation creates its own space to save its parameters or local variables, there is no problem. By the way are you sure that the invocation of the method ocurred in a multithreaded enviroment?. Maybe they are only enqueued.
SCJP2. Please Indent your code using UBB Code
Weeds: because mother nature refuses to be your personal bitch. But this tiny ad is willing:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
|