i have a student question:
i would like to have an advice and some explanation about visibility problem in multicore if there is one.
I use Registry pattern in my SpringBoot Application to map different scanners instances to their names.
Configuration:
@Bean
public WebScannerExecutor webScannerExecutor(final WebScannerClientProcessor webScannerClientProcessor) {
return new WebScannerExecutor(webScannerClientProcessor);
}
@Bean
public TLSScannerExecutor tlsScannerExecutor(final @Value("${tls.scanner.path}") String path, final BashProcessor bashProcessor) {
return new TLSScannerExecutor(path, bashProcessor);
}
@Bean
public ScanExecuterRegistry executerRegistry(final WebScannerExecutor webScannerExecutor, final TLSScannerExecutor tlsScannerExecutor) {
final ScanExecuter[] arr = new ScanExecuter[] {webScannerExecutor, tlsScannerExecutor};
return new ScanExecuterRegistry(arr);
}
Registry:
public class ScanExecuterRegistry {
private final ImmutableMap<ScannerType, ScanExecuter> registry;
public ScanExecuterRegistry(final ScanExecuter... executors) {
this.registry = ImmutableMap.<ScannerType, ScanExecuter> builder().putAll(Arrays.asList(executors).stream().collect(Collectors.toMap(ScanExecuter::getType, e -> e))).build();
}
Right now i am using ImmutableMap from Guava and i am pretty sure there is no problem. But...
private final Map<ScannerType, ScanExecuter> registry;
If i take instead of ImmutableMap just a final map (immutable reference but not content), could any problem rise? Any problem with thread caches, visibility et cetera in multicore systems (even with the usage of singeltons)?
EDITED:
All good as long as you don't modify the content
Exactly that i would like to get explained. I am not so good with java memory model yet.
I can change the content of map, only in spring configuration class adding a new scanner. So the application will restart in any case. Can there still be a problem?