I am implementing a producer consumer scenario using a BlockingQueue.
This is my consumers run method:
@Override
public void run() {
try {
Message msg;
System.out.println("Consumer started");
//consuming messages until exit message is received
while(!(msg=queue.take()).getMsg().equalsIgnoreCase("exit")) {
//
}
} catch (InterruptedException e) {
e.printStackTrace();
}
and I intend to call the below method when I get something out of the queue, but here is a condition. I want to run ony one isntance of this method. I dont want to consume from the queue till I get a return from the below method.
I have been struggling as in how do I contain this in the while loop.
public boolean runStrategy(String msg) {
ExecutionContext executionContext = new ExecutionContext();
String[] filePathArray = msg.split("/");
String campaignForType = filePathArray[6];// .equals("Profiles")/events etc etc
if (campaignForType.equalsIgnoreCase("Profiles")) {
executionContext.setExecutionStrategy(new ProfileUploadExecutionStrategy());
return executionContext.executeCampaign(filePathArray, msg);
} else if (campaignForType.equalsIgnoreCase("Events")) {
/* executionContext.setExecutionStrategy(new EventExecutionStrategy());
executionContext.executeCampaign(filePathArray, msg.toString());*/
return true;
}
return true;
}