|
![]() |
SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
Steve
SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
Steve
So you could fix it a number of ways, but to know which is appropriate I would need to know why you need NonWatch at all and who is supposed to see what values.
Is it the 'current thread's' value? If this is part of the web app we are talking about, would it be each user which needs to have a consistent value?
SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
Amandeep Singh wrote:
Is it the 'current thread's' value? If this is part of the web app we are talking about, would it be each user which needs to have a consistent value?
It is not a web application. the front end is html/javascript and the backend is pure java. Yes, each user needs to have its own consistent value.
Steve
If that is not the case, and you can only have one EntryManager for the entire application then you are better off NOT using a variable to store the boolean value in. Instead, re-calculate it each time. It will be safer and cleaner.
SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
Amandeep Singh wrote:This code will not help me in my situation. I think in last example, you got my intention wrong.
If that is not the case, and you can only have one EntryManager for the entire application then you are better off NOT using a variable to store the boolean value in. Instead, re-calculate it each time. It will be safer and cleaner.
Yes in my situation, i am using a 1 EntryManager for the the entire application.
So i understand from you, that class variables are not safe to keep the result stored in a multi-threaded access.
The reason i am using class variable because in this way, i do not have to pass parameters in and around the methods. Just using class variable will solve my problem. Since it is a multithreaded access, things can go wrong.
my Solution-
it would be to pass local parameters only in and around the method.
out of curiosity Question- In case of beans, we do make class variables. But we do new Bean(), that's why it is safe there in case of multi-threaded applications.
Steve
SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
You save more money with a clothesline than dozens of light bulb purchases. Tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
|