aspose file tools*
The moose likes Spring and the fly likes Spring scheduler Task Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring scheduler Task" Watch "Spring scheduler Task" New topic
Author

Spring scheduler Task

Baskar Sikkayan
Greenhorn

Joined: Oct 06, 2011
Posts: 16
Hi,
I use Spring Quartz scheduler(Clustered) in my application as follows. Inside the scheduler, i instantiate a thread class to spawn a new thread for each record and inside the thread class, i use reference of other bean class using wiring concept. As the thread class inside the scheduler is instantiated using the new operator, the dependency injection inside the thread class is not working. Is there any way, we can achieve this?

From applicationContext.xml,



CampaignNow.java class,



Thread class,



Thanks,
Baskar.S
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1666
    
    7

There are a couple of ways you could handle this. My first suggestion would be to make an async service bean.



Then autowire AsyncCamapignService in your CampaignNowJob and call the method.

dont forget to add



to your XML configuration.

see the docs for more info on @Async
http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/scheduling.html#scheduling-annotation-support-async


[How To Ask Questions][Read before you PM me]
Baskar Sikkayan
Greenhorn

Joined: Oct 06, 2011
Posts: 16
Hi,
Thanks for the info.

I may not be able to go with this as i use ThreadPoolExecutor and the excute method needs runnable implementor. Also, i can configure many things in ThreadPoolExecutor. Is there any other equivalent class in Spring?

Thanks,
Baskar.S
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1666
    
    7

You can specify an executor on the annotation-driven tag. Alternatively you can specify any executor on the annotation itself see the documentation here:
http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/scheduling.html#scheduling-annotation-support-qualification

The executor provided must of course must have a bean definition in your context. It can be any Executor of type java.util.concurrent.Executor or org.springframework.core.task.TaskExecutor. Since ThreadPoolExecutor meets this criteria there is no reason you could not use it. Be aware if there are multiple methods within the class needing the async behavior this annotation can be applied at the class level as well.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring scheduler Task