Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Reduce DomainClass autowiring call overhead (it showed up in top bloc…

…king methods while profiling)

Conflicts:

	grails-core/src/main/groovy/org/codehaus/groovy/grails/commons/spring/GrailsRuntimeConfigurator.java
  • Loading branch information...
commit 8e29470aa640d52b26ae331ba1e44cae32583780 1 parent 5e026c8
Lari Hotari lhotari authored
9 grails-bootstrap/src/main/groovy/grails/util/Environment.java
@@ -93,6 +93,7 @@
93 93 TEST_ENVIRONMENT_SHORT_NAME, Environment.TEST.getName());
94 94 private static Holder<Environment> cachedCurrentEnvironment = new Holder<Environment>("Environment");
95 95 private static final boolean cachedHasGrailsHome = System.getProperty("grails.home") != null;
  96 + private static boolean initializingState = false;
96 97 private String name;
97 98
98 99 Environment() {
@@ -400,8 +401,14 @@ public static boolean isInteractiveMode() {
400 401 * @return Whether interactive mode is enabled
401 402 */
402 403 public static boolean isInitializing() {
403   - return Boolean.getBoolean(INITIALIZING);
  404 + return initializingState;
404 405 }
  406 +
  407 + public static void setInitializing(boolean initializing) {
  408 + initializingState=initializing;
  409 + System.setProperty(INITIALIZING, String.valueOf(initializing));
  410 + }
  411 +
405 412 /**
406 413 * @return true if the reloading agent is active
407 414 */
4 grails-core/src/main/groovy/org/codehaus/groovy/grails/commons/spring/GrailsRuntimeConfigurator.java
@@ -166,9 +166,9 @@ public WebApplicationContext configure(ServletContext context, boolean loadExter
166 166
167 167 application.setMainContext(webSpringConfig.getUnrefreshedApplicationContext());
168 168
169   - System.setProperty(Environment.INITIALIZING, "true");
  169 + Environment.setInitializing(true);
170 170 ctx = (WebApplicationContext) webSpringConfig.getApplicationContext();
171   - System.setProperty(Environment.INITIALIZING, "");
  171 + Environment.setInitializing(false);
172 172
173 173 pluginManager.setApplicationContext(ctx);
174 174 pluginManager.doDynamicMethods();
3  ...ore/src/main/groovy/org/codehaus/groovy/grails/commons/spring/ReloadAwareAutowireCapableBeanFactory.java
@@ -182,6 +182,9 @@ protected boolean isExcludedFromDependencyCheck(PropertyDescriptor pd) {
182 182 @Override
183 183 public void autowireBeanProperties(Object existingBean, int autowireMode,
184 184 boolean dependencyCheck) throws BeansException {
  185 + if(Environment.isInitializing()) {
  186 + return;
  187 + }
185 188 if(autowireMode == AUTOWIRE_BY_NAME) {
186 189 if(DISABLE_AUTOWIRE_BY_NAME_OPTIMIZATIONS || dependencyCheck || existingBean instanceof Aware) {
187 190 super.autowireBeanProperties(existingBean, autowireMode, dependencyCheck);
6 ...ls-plugin-domain-class/src/main/groovy/org/codehaus/groovy/grails/plugins/DomainClassGrailsPlugin.groovy
@@ -203,9 +203,11 @@ class DomainClassGrailsPlugin {
203 203 return gormValidationApi
204 204 }
205 205 }
  206 +
  207 + AutowireCapableBeanFactory autowireCapableBeanFactory=ctx.autowireCapableBeanFactory
  208 + int byName=AutowireCapableBeanFactory.AUTOWIRE_BY_NAME
206 209 metaClass.static.autowireDomain = { instance ->
207   - if(!Environment.isInitializing())
208   - ctx.autowireCapableBeanFactory.autowireBeanProperties(instance,AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false)
  210 + autowireCapableBeanFactory.autowireBeanProperties(instance, byName, false)
209 211 }
210 212 }
211 213 }

0 comments on commit 8e29470

Lari Hotari

This used to be a bug. Autowiring stopped working in other Grails apps in the same JVM while some Grails app was starting up. This change also fixes that problem.

Please sign in to comment.
Something went wrong with that request. Please try again.