Announcement Announcement Module
Collapse
No announcement yet.
Spring async listeners instead of threads? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring async listeners instead of threads?

    Spring Provides e Application Listeners to handle Application Events. I want to get rid of my Thread classes and use these listeners for event handling .Any hint to start?Can I do this?

    Code:
    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;
        }
    }

    I have a requestmanager class.

    Code:
    Class RequestManager{
    
    private FinderService OfferFinder;
    public int createRequest(Request Request){
    // create my request
    OfferFinder.notifyFinder();
    
    
    }
Working...
X