File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes How to start a Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "How to start a "daemon thread" in a Spring application" Watch "How to start a "daemon thread" in a Spring application" New topic
Author

How to start a "daemon thread" in a Spring application

Arthur Kopatsy
Greenhorn

Joined: Apr 13, 2010
Posts: 1
Hi,

I am new to both Spring and java in general and here is what I want to do.
I have a message bus internally, where events are posted and I need a thread that will be listening on this bus.
This thread must have access to the other beans (to update the DB for instance).

Here is my problem:
I am planning to use Spring for the dependency injection including for my "daemon bean". However, it looks like I need to use a contextlistener to start up my thread. If I understand this correctly, I will not be able to leverage the dependency injection if I start my thread this way.

My question is therefore the following:
How to start a long living thread at application startup time in a Spring application?

Your help would be greatly appreciated.

Thanks,

Arthur
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

To Be honest, your best solution is to use Spring Integration or Spring JMS. Both have the ability to create a Channel/Queue which you can have a POJO bean listening in on that channel. so whenever something is placed on the channel, the code will run.

Check out the documentation for both at www.springframework.org

THanks

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to start a "daemon thread" in a Spring application