2011-07-27 67 views
0

我對grails應用程序有疑問。我有一個控制器,在服務器端做很多工作,可能需要幾分鐘才能完成任務。我擔心如果用戶在代碼運行時點擊刷新,它會嘗試再次運行代碼。我將如何防止這種情況。下面是一些僞代碼如何防止grails服務器端代碼在運行時運行

def refreshDb = {  
    requeryDataBase() 
} 

    public void requeryDatabase(){ 

    ....some long process here 
    } 

因此,如果它已經在運行,我將如何防止requeryDataBase()運行?

感謝您的任何幫助或見解! jason

回答

1

如果您希望多個用戶能夠使用控制器,使用會話對象可以像下面那樣工作。

  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

謝謝。這似乎做到了! – jason