0
我的RESTful基于Spring的Web服务收到差异化的用户请求,比如金牌,银牌和铜牌,其中金牌请求具有最高优先级,铜牌最低。所以我想实现一些简单类型的差异化服务配置。这可能是最简单的(我会说几乎嘲笑)战略实施?我的REST风格的Web服务的最简单的QoS策略
我在考虑如果我服务更多的优先级时阻塞较少的优先级。像这样的东西
@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;
}
}
这是否合理?或者它有一些不良的副作用? 您是否推荐更好的策略?