开发者

How to prevent grails server sided code from running if it is already running

I have a question about a grails application. I have a controller that does a lot of work, on the server side, and can take several mi开发者_如何转开发nutes to complete its task. I'm concerned that if the user hits refresh while the code is running, it will try to run the code again. How would i prevent this. below is some psuedo code

 def refreshDb = {      
    requeryDataBase()
}

  public void requeryDatabase(){

    ....some long process here
  }

so, how would i prevent requeryDataBase() from running if it is already running?

thanks for any help or insight! jason


You should look at submitting a form token with the web request. It stores a one-use token so that multiple submissions are not allowed and can be detected. See the grails framework docs on handling duplicate submissions for more details.


If you want multiple users to be able to use the controler something like the following could work using the session object.

  public void requeryDatabase(){
if (session['queryRunning']==false) {
   session['queryRunning']=true
    ....some long process here
session['queryRunning']=false //set to false so the user can execute the controller again
}
 else {
   //Put code to notify the user to be pacient here
}
  }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜