All entries for Tuesday 07 November 2006

November 07, 2006

Singleton in Spring

Follow-up to Singleton in Spring from Oracle/Java/Others

A spring bean default to be singleton. The following class is a Spring bean

Class Transform{
   private Map errors = new HashMap();
   public void setErrors(final Map errors) {
        this.errors = errors;
  }
  public void transform(){
   if(errors.isEmpty()){
    // do something
  } 
}

}

One thread call setErrors() and call transform() to finish it job. The next thread has to remember to call the setErrors() before call transform(), otherwise it will get the values of previous thread.

might safter to change the method signature to

Class Transform{
  public void transform(Errors errors){
   if(errors.isEmpty()){
    // do something
  } 
}
}

So you do not need to call the setErrors(), which is forgettable.


Search this blog

Search Warwick Blogs

 

Tags

Most recent comments

  • Oracle 11g is the clear leader in this area. Oracle has invested heavily into self–tuning capabiliti… by shaane on this entry
  • All the features are very nice.I like Repair Advisors the most.Oracle 10G introduced some of the dat… by lucy on this entry
  • "logical standby failed to re–start, I am also getting the same error. I have search on internet and… by anemia on this entry
  • Thanks for the nice information because from last three days i am stuck on this problem…. by robot vacuum on this entry
  • So what happen City speed dating when you tried this coding once in your PC.. Please tell me so i am… by John Bergeron on this entry
Not signed in
Sign in

Powered by BlogBuilder
© MMXXII