From 7163e0bac1b8cc8e0f6ac9762cbb1f97be02761f Mon Sep 17 00:00:00 2001 From: michaeloffner Date: Fri, 6 Dec 2024 13:39:26 +0100 Subject: [PATCH] LDEV-4602 - shifting the sync --- .../java/lucee/runtime/PageSourceImpl.java | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/lucee/runtime/PageSourceImpl.java b/core/src/main/java/lucee/runtime/PageSourceImpl.java index f387ab5a77..0c3997225f 100755 --- a/core/src/main/java/lucee/runtime/PageSourceImpl.java +++ b/core/src/main/java/lucee/runtime/PageSourceImpl.java @@ -363,14 +363,18 @@ private Page loadPhysical(PageContext pc, Page page) throws TemplateException { Resource classRootDir = mapping.getClassRootDirectory(); Resource classFile = classRootDir.getRealResource(getJavaName() + ".class"); boolean isNew = false; - synchronized (this) { + { // new class if (flush || !classFile.exists()) { - LogUtil.log(pc, Log.LEVEL_DEBUG, "compile", "compile [" + getDisplayPath() + "] no previous class file or flush"); + synchronized (this) { + if (flush || !classFile.exists()) { + LogUtil.log(pc, Log.LEVEL_DEBUG, "compile", "compile [" + getDisplayPath() + "] no previous class file or flush"); - pcn.set(page = compile(config, classRootDir, null, false, pc.ignoreScopes())); - flush = false; - isNew = true; + pcn.set(page = compile(config, classRootDir, null, false, pc.ignoreScopes())); + flush = false; + isNew = true; + } + } } // load page else { @@ -405,17 +409,21 @@ private Page loadPhysical(PageContext pc, Page page) throws TemplateException { pcn.reset(); } if (page == null) { - LogUtil.log(pc, Log.LEVEL_DEBUG, "compile", "compile [" + getDisplayPath() + "] in case loading of the class fails"); - pcn.set(page = compile(config, classRootDir, null, false, pc.ignoreScopes())); - isNew = true; + synchronized (this) { + LogUtil.log(pc, Log.LEVEL_DEBUG, "compile", "compile [" + getDisplayPath() + "] in case loading of the class fails"); + pcn.set(page = compile(config, classRootDir, null, false, pc.ignoreScopes())); + isNew = true; + } } } // check if version changed or lasMod if (!isNew && (srcLastModified != page.getSourceLastModified() || page.getVersion() != pc.getConfig().getFactory().getEngine().getInfo().getFullVersionInfo())) { - isNew = true; - LogUtil.log(pc, Log.LEVEL_DEBUG, "compile", "recompile [" + getDisplayPath() + "] because unloaded page has changed"); - pcn.set(page = compile(config, classRootDir, page, false, pc.ignoreScopes())); + synchronized (this) { + isNew = true; + LogUtil.log(pc, Log.LEVEL_DEBUG, "compile", "recompile [" + getDisplayPath() + "] because unloaded page has changed"); + pcn.set(page = compile(config, classRootDir, page, false, pc.ignoreScopes())); + } } page.setPageSource(this); page.setLoadType(LOAD_PHYSICAL); @@ -459,7 +467,7 @@ private boolean isLoad(byte load) { return page != null && load == page.getLoadType(); } - private synchronized Page compile(ConfigWeb config, Resource classRootDir, Page existing, boolean returnValue, boolean ignoreScopes) throws TemplateException { + private Page compile(ConfigWeb config, Resource classRootDir, Page existing, boolean returnValue, boolean ignoreScopes) throws TemplateException { try { return _compile(config, classRootDir, existing, returnValue, ignoreScopes, false); }