Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring异步侦听器而不是线程?_Spring - Fatal编程技术网

Spring异步侦听器而不是线程?

Spring异步侦听器而不是线程?,spring,Spring,我有一个线程来处理我的请求:基本上,当我创建一个请求时,我会找到为特定请求提供的服务。我正在使用线程。我想摆脱线程,使用spring侦听器和任务执行器。我可以这样做吗?有什么例子吗 public class FinderServiceImpl implements FinderService, Runnable { private RequestManager requestManager; private boolean continueRunning = true;

我有一个线程来处理我的请求:基本上,当我创建一个请求时,我会找到为特定请求提供的服务。我正在使用线程。我想摆脱线程,使用spring侦听器和任务执行器。我可以这样做吗?有什么例子吗

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();


}