After trying different solutions we implement like this. We create a object to store the objects to share:
public class JobCache {
private HashMap<TypeClass,Set<String>> ExistingNames;
private final UUID id;
...
The id field is final to be used for synchronization the access to the attribute existingNames. And we modified the cache between the differents jobs using the next statement:
synchronized (jobCache.getId()){
jobCache.addNames(names,TypeClass.TYPE1);
}
We know this is not totally thread-safe but under our environment it is (because of the way how the jobs are created).
For getting the names (even if it is not needed, only to be sure, we use this:
synchronized(jobCache.getId()){
this.names = jobCache.getExistingNames(TypeClass.TYPE1);
}
Maybe it is not the ideal and most elegant solution but it work for us.