i try to implement some rest api for read mails service. now i have a command that can stop/run the service. after i run the service for some reason when i update my config file in the runService method into "RUNNING" i still get that the status of the service is "ONHOLD" and i dont undersatnd why. there for the do while loop terminated only after 1 iteration.
there is a delay while we working with files inside the program code? this is my full code:
Queryable
答案 0 :(得分:1)
我真的不了解你的问题,但至少我认为你在 runService 方法中遇到了问题: 注意:在以“ < - ”
开头的代码中添加了一些注释 String stat = prop.getProperty("status"); <-- you read the property here
if(stat.equals(status.FINISHED.toString()) || stat.equals(status.ONHOLD.toString()))
{
updateConfigfile(username+".properties","status",status.RUNNING.toString());
do{
i++;
model.addAttribute("msg","inside loop"+" "+"Counter is:"+" "+i+" "+"status is =" +prop.getProperty("status")); <-- status contains FINISHED or ONHOLD! It is the same as using stat variable.
}while(prop.getProperty("status").equals(status.RUNNING.toString())); <--contains FINISHED or ONHOLD! so, always return false
}else{
model.addAttribute("msg","Service is already running");
}
换句话说,如果您更改文件,则需要再次读取该文件,以便将更新的属性更新为属性对象。
希望这有帮助!
我的意思是这提到了我的上一条评论!
String stat = prop.getProperty("status");
if(stat.equals(status.FINISHED.toString()) || stat.equals(status.ONHOLD.toString()))
{
updateConfigfile(username+".properties","status",status.RUNNING.toString());
prop.setProperty("status",status.RUNNING.toString());
i++;
model.addAttribute("msg","inside loop"+" "+"Counter is:"+" "+i+" "+"status is =" +prop.getProperty("status"));
}else{
model.addAttribute("msg","Service is already running");
}