0

I've got the service and it's implementation annotated with @Service. It works well in one-threaded app, but now I should do some logic from another thread using this service. This is my code:

import org.springframework.beans.factory.annotation.Autowired;

import ru.tenet.smsc.form.MassSMSForm;
import ru.tenet.smsc.service.SaveBatchService;


public class MassSmsRunnable implements Runnable {

    private MassSMSForm massSMSForm;

    private String userName;

    @Autowired
    SaveBatchService saveBatchService;

    public MassSmsRunnable(MassSMSForm massSMSForm, String userName) {
        this.massSMSForm = massSMSForm;
        this.userName = userName;
    }

    @Override
    public void run() {         

        saveBatchService.sendMass(massSMSForm, userName); //here it is
        saveBatchService.save();
    }

}

But NullPointerException is all that I've got:

Exception in thread "Thread-3" java.lang.NullPointerException
    at ru.tenet.smsc.thread.MassSmsRunnable.run(MassSmsRunnable.java:31)
    at java.lang.Thread.run(Thread.java:744)

So, how can I solve this?

Tony
  • 3,605
  • 14
  • 52
  • 84

1 Answers1

0
 @Component
 public class MassSmsRunnable implements Runnable 

And whereever you are using the runnable

@Inject
private MassSmsRunnable massSmsRunnable;

In MassSmsRunnable you need to inject massSMSForm and username in similar manner.

Pratik Shelar
  • 3,154
  • 7
  • 31
  • 51
  • But my running code looks like this: Thread t=new Thread(new MassSMSRunnable()); Can I inject it the way you post? – Tony Aug 05 '14 at 15:29
  • with this you just instantiated MassSMSRunnable, you need to also inject the dependencies massSMSForm and username – Pratik Shelar Aug 06 '14 at 07:08