public Foo getFoo(){
Foo foo = null;
synchronized(fooList){
if(fooList.size() > 0){
foo = fooList.remove(0);
}
}
return foo;
}
Since foo is declared outside of the synchronized block, does the potential exist of returning bad data?
Each thread instance calling
getFoo()will have its ownfooinstance. Thusfoois thread safe and doesn’t need synchronization.