I highly appreciate all your comets..
Does this mean if my bean contain state information (instance variables), still I can safely declare it as a singleton, when manged within spring framework?
For example consider following class;
public class Class1 {
private String userId;
public String getUserId() {
return userId;
}
public void setUserId(String string) {
userId = string;
}
}
If I use this within spring context with default behaviour (singleton=true), If one of the client of this bean call the setUserId() and change the state of userId. Then if the next client call the getUserId(), is it going to get the modified state of previous client? (this is not my intention anyway). So in this type of scenario do I have to made this bean prototype?
I would like if anyone explain "Per-ApplicationContext singletons" in the light of my bean example above.
Can anyone provide me with a simple rule (rule of thumb) , that guide whether my bean is a candidate to be declared as a singleton or otherwise.
Thanks in advance.