My RESTful Spring based Web Service receives differentiated user requests, say Gold, Silver and Bronze, where Gold requests have maximum priority, Bronze lowest one. So I want to implement some simple type of differentiated service provisioning. Which could be the simplest (I would say almost mocked) strategy to implement?
I'm thinking about blocking less priority for some amount of time if i'm serving more priority one. Something like this
@Controller
public class MyController {
@Autowired
private MyBusinessLogic businessLogic;
private static final int GOLD=0;
private static final int SILVER=1;
private static final int BRONZE=2;
private volatile int [] count = new int[3];
@RequestMapping
public String service(@RequestBody MyRequest request) {
count[request.getType()]++;
for(int i=0; i<request.getType(); i++)
if(count[i]>0)
Thread.sleep(500);
String result = businessLogic.service(request);
count[request.getType()]--;
return result;
}
}
Is it reasonable? Or has it some undesirable side-effect? Do you recommend a better strategy?