8

I have a traditional 3-tier application with spring. One of my repositories needs > 3 minutes for initialization so I thought about some multi-threaded approach in order to speed up the whole process - I think most service and controllers in my dependency tree can already be started so only a few must wait for the last repository to come up.

Is there any best practice approach?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Jan
  • 2,803
  • 6
  • 36
  • 57

1 Answers1

4

Use Spring's Executor abstraction. And if you are within a app server then I suggest you use application server's work-manager (spring supports it). For e.g. WebSphere app server and Weblogic both support registering the workmanagers in JNDI. You can then pass the jndi name to spring. Task Executors

Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327
  • We currently use Tomcat - does it also support such stuff? – Jan Nov 03 '10 at 15:13
  • I do not think tomcat supports the work manager. But in tomcat you are good with using other executors provided by spring: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/scheduling.html – Aravind Yarram Nov 03 '10 at 15:14
  • 1
    I see only examples for annotating methods, not for the actual initialization. Do I need custom code for handling the concurrent context initialization? – Jan Nov 05 '10 at 15:25
  • May be. it depends on your use case. Identify which beans are taking longer to initialize and try to initialize in async. Go through section "The @Async Annotation" from http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/scheduling.html – Aravind Yarram Nov 05 '10 at 15:45