how to start a thread in Spring bean

Viewed 9878

I want to run a thread in spring application

    @Component
    public class MyServiceCreationListener {


        public void startThread() {

            Thread t = new Thread(new MyThread());
            t.start();

        }
    }

Here i used Thread t = new Thread(new MyThread()); This is wrong way.

Please provide solution for this to spring manage MyThread like a spring bean so we can autowire it into other beans and by calling start() method we can access it

Here is Thread class

@Component
public class MyThread implements Runnable {

    public void run() {

        System.out.println("Inside run()");

    }

}
1 Answers
Related