Satish
unread,Apr 7, 2011, 11:39:36 AM4/7/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to CheckThread Discussion Forum
Hi,
All methods in Dictionary class below are not thread-safe. I have
added @ThreadSafe annotation hoping that CheckThread would flag the
methods need to be synchronized, but it is not. What am I doing
wrong?
package com.test;
import java.util.ArrayList;
import java.util.List;
import org.checkthread.annotations.ThreadSafe;
@ThreadSafe
public class Dictionary {
public List<String> terms = new ArrayList<String>();
@ThreadSafe
public void addIfNotExist(final String input) {
if (!this.terms.contains(input)) {
this.terms.add(input);
}
}
@ThreadSafe
public boolean isExist(final String input){
return this.terms.contains(input);
}
@ThreadSafe
public void remove(final String input){
this.terms.remove(input);
}
@ThreadSafe
public String toString(){
final StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(terms.toString());
return stringBuffer.toString();
}
}
Thanks,
Satish