I have a class that uses Hiberante for database operations and need it to be thread-safe. I am trying refactor the code to use Atomic Variables with its Operations instead of having a synchronized method due to locking as it is breaking the application due to slow performance (a lot of threads are in play) on a high volume of requests but I am having issues with a variable with @Enumeration to refactor to AtomicReference due to an exception:
Attribute [com.gateway.domain.ImportTypeDetail.importFrequency] was annotated as enumerated, but its java type is not an enum [java.util.concurrent.atomic.AtomicReference]
Code before refactor:
@Column(name = Constants.Columns.IMPORT_FREQUENCY)
@Enumerated(EnumType.STRING)
private ImportFrequency importFrequency;
I refactored to:
@Column(name = Constants.Columns.IMPORT_FREQUENCY)
@Enumerated(EnumType.STRING)
private AtomicReference<ImportFrequency> importFrequency = new AtomicReference<>(ImportFrequency.UNKNOWN);
Is it possible to implement AtomicReference in the scenario? EnumType only options are ORDINAL
and STRING
for type property or integer and type property or string respectively.