Spring异步侦听器而不是线程?
我有一个线程来处理我的请求:基本上,当我创建一个请求时,我会找到为特定请求提供的服务。我正在使用线程。我想摆脱线程,使用spring侦听器和任务执行器。我可以这样做吗?有什么例子吗Spring异步侦听器而不是线程?,spring,Spring,我有一个线程来处理我的请求:基本上,当我创建一个请求时,我会找到为特定请求提供的服务。我正在使用线程。我想摆脱线程,使用spring侦听器和任务执行器。我可以这样做吗?有什么例子吗 public class FinderServiceImpl implements FinderService, Runnable { private RequestManager requestManager; private boolean continueRunning = true;
public class FinderServiceImpl implements FinderService, Runnable {
private RequestManager requestManager;
private boolean continueRunning = true;
private Thread service;
public RequestManager getRequestManager() {
return RequestManager;
}
public void setRequestManager(
RequestManager requestManager) {
this.requestManager = requestManager;
}
public FinderServiceImpl() {
service = new Thread(this);
service.start();
}
public void run() {
while (continueRunning) {
try {
synchronized (service) {
service.wait();
}
} catch (InterruptedException e) {
LOG.error("Error in finder service: " + e);
}
if (requestManager != null) {
LOG.debug("CALLING the RequestManager");
requestManager.findForAllRequest();
LOG.info("Finished Finding the Offer. !!");
}
}
}
@Override
public void notifyFinder() {
LOG.debug(" Notifier is called the Service to Find ");
synchronized (service) {
service.notify();
}
}
@Override
public void scheduledFinding() {
synchronized (service) {
service.notify();
}
}
@Override
public void startService() {
continueRunning = true;
if (!service.isAlive()) {
LOG.debug("Starting the finder service");
service = new Thread(this);
service.start();
}
}
@Override
public void stopService() {
LOG.debug("Stopping the finder service");
this.continueRunning = false;
}
}
我有一个requestmanager类
Class RequestManager{
private FinderService OfferFinder;
public int createRequest(Request Request){
// create my request
OfferFinder.notifyFinder();
}