help: enum cause failure in multi thread run
I really like Java enums, so I use it a lot. Probably I have abused it.
Below is my enum ABC_ENUM,java. Is that ok? My understanding is
ABC_ENUM.A is one static object, ABC_ENUM.B is another static object, etc.
If I have two threads running the same method, but on different data. If
one thread's ABC_ENUM.A boolean value is changed, another thread's
ABC_ENUM.A value will be changed too??!! What should I do if I want that
change(ABC_ENUM.A boolean value changed to "true") is only effective
within the current thread, not affect another thread?
If this is poor design, can you give me some recommendation? Thank you.
public enum ABC_ENUM
{
A("A", false),
B("B", false),
C("C", true);
private String _techName;
private boolean _boolValue;
private ABC_ENUM(final String techName, final boolean boolValue)
{
_techName = techName;
_boolValue = boolValue;
}
public String techniqueName()
{
return _techName;
}
public void setBoolValue(final boolean boolValue)
{
_boolValue = boolValue;
}
public boolean boolValue()
{
return _boolValue;
}
@Override
public String toString()
{
return _techName + "[" + _boolValue + "]";
}
/**
* Reset these constants' boolVaue to their original values to
erase the changes made by previous run.
*/
public static void reSetToDefaultValues()
{
A._boolValue = false;
B._boolValue = false;
C._boolValue = true;
}
}