Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static final AtomicReference<Map<String, File>> templates = new AtomicReference<>();
- private static Map<String, File> getTemplatesMap() {
- Map<String, File> map = templates.get();
- if (map == null) {
- Collection<File> files = VisualDesignerPluginUtil.getFiles(
- VaadinDesignerConstants.TEMPLATE_FOLDER, "html");
- map = new LinkedHashMap<String, File>(files.size());
- for (File file : files) {
- map.put(FilenameUtils.getBaseName(file.getName()), file);
- }
- // templates could be already filled by the separate thread, so
- // previous work could be not needed, but it's rare and there is no
- // any thread race condition.
- if (templates.compareAndSet(null, map)) {
- return map;
- } else {
- return templates.get();
- }
- } else {
- return map;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement