I have a thread to process my request:Basically when i create a request i find the offered services for particular request.I am using thread.I want to get rid of thread and use spring listeners and task executor(Can I).How can i do this.?Any example
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.
Class RequestManager{
private FinderService OfferFinder;
public int createRequest(Request Request){
// create my request
OfferFinder.notifyFinder();
}
精彩评论