ThreadSafe - Race Condition Not Detected

98 views
Skip to first unread message

Satish

unread,
Apr 7, 2011, 11:39:36 AM4/7/11
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
Reply all
Reply to author
Forward
0 new messages