Jayasagar
Jayasagar

Reputation: 2066

How can I Optimize Spring Framework usage for Google App Engine Applications

Google App Engine frontend instances are dynamically scaled. That means App Engine automatically creates new instances when load increases and turns off instances when they are not being used. Reloading instances may result in additional latency for users. Frontend instances also have a 60 seconds deadline to complete a given request.

As I am using Spring MVC and Spring IOC in my GAE application, to Optimize Spring Framework usage, I have gone through Best Practices for App Engine Applications.

In that link I am completely confused with the section Reducing or Avoiding the Use of Relationship Autowiring . It says automatic wiring can significantly the time required to resolve the beans during application initialization time, so they suggest autowire byName instead of using autowire byType .

So my question is How autowire byName reduces bean resolving time ?? . And also I would like to know is there any better way to inject beans ?. Is there any best practices for Spring IOC to reduce application initialization time.

Upvotes: 11

Views: 1447

Answers (2)

venergiac
venergiac

Reputation: 7717

Let me give a reply to all the answers

So my question is How autowire byName reduces bean resolving time ??

already explained by apurvc, in particular if you use interface or you use massive class inheritance Spring will have to inspect the hierarchy of classes

I would like to know is there any better way to inject beans ?

  1. Yes, do not inject bean by autowire but use set or get property, as you can; I use this policy.
  2. Avoid autoscan component
  3. Use singleton or bean pools or factory to reuse or construct object

Is there any best practices for Spring IOC to reduce application initialization time.

  1. use lazy initialization (@Lazy annotation)
  2. put not dependent bean at the top of XML definition

But you do not really need these solutions if you are JEE developer.

Upvotes: 4

apurvc
apurvc

Reputation: 750

Autowire "byType" obviously have to use some mechanism (and some processing )to correctly identify the bean whereas using "byName" provide a direct identification.

Take an analogy of a group of many breed of cats and dogs. To find the terrier out of the group you will have to first identify all breeds however when you use name of dogs it is much easier and improve the identification.

Spring does scanning of the classes for annotations which are inside package defined in "context:component-scan" if there are many classes in package it will take a while during start-up of an application hence it is suggested to use autowire byName.

Upvotes: 7

Related Questions