如果grails服务器端代码已经在运行,如何防止其运行

如果grails服务器端代码已经在运行,如何防止其运行,grails,groovy,grails-controller,Grails,Groovy,Grails Controller,我有一个关于grails应用程序的问题。我有一个控制器,它在服务器端做很多工作,可能需要几分钟才能完成它的任务。我担心,如果用户在代码运行时点击“刷新”,它会再次尝试运行代码。我该如何防止这种情况。下面是一些psuedo代码 def refreshDb = { requeryDataBase() } public void requeryDatabase(){ ....some long process here } 那么,如果requeryDataB

我有一个关于grails应用程序的问题。我有一个控制器,它在服务器端做很多工作,可能需要几分钟才能完成它的任务。我担心,如果用户在代码运行时点击“刷新”,它会再次尝试运行代码。我该如何防止这种情况。下面是一些psuedo代码

 def refreshDb = {      
    requeryDataBase()
}

  public void requeryDatabase(){

    ....some long process here
  }
那么,如果requeryDataBase()已经在运行,我如何防止它运行呢

感谢您的帮助或见解!
jason

如果您希望多个用户能够使用控制器,可以使用session对象执行以下操作

  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
}
  }

如果您希望多个用户能够使用控制器,那么使用会话对象可以执行如下操作

  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
}
  }

您应该考虑在web请求中提交一个。它存储一个一次性令牌,因此不允许多次提交,并且可以检测到多次提交。请参阅。

您应该查看随web请求一起提交。它存储一个一次性令牌,因此不允许多次提交,并且可以检测到多次提交。看