public void setUploadFolder(String upload_folder) {
if(!StringUtils.isEmpty(upload_folder)) {
destinationFolder = new File(upload_folder);
destinationFolder.createNewFile();
}
}
這是當使用者上傳檔案後,開啟一個檔案然後準備存檔,為什麼這段程式有問題? 因為,web 程式是多人使用的系統,每個人登入會產生自己的 thread,如果兩個人同時執行到上述的程式,就會產生 race condition,解決的辦法就是加上同步機制,以確保這段程式碼 thread-safe。【每日一字】
to have no choice but to: to be forced to do something; to have no other option but ...; to have no choice to do anything except ... (除了…外別無選擇,只好,不得不)
* We were lost in the forest, very hungry and tired, but we had no choice but to continue walking to try to get home.
(資料來源: ESL Podcast 287)
沒有留言:
張貼留言