-2
我創建了搜索源文件夾中的文件的程序。如果它找到任何文件,它會處理該文件並將文件移動到目標文件夾,並在源文件夾中查找新文件。就像它必須繼續檢查文件的源文件夾。我已經使用線程來查找源文件夾中的文件。我面臨的問題是在文件進程線程停止期間任何異常拋出。即使在文件處理期間拋出異常,我也希望線程正在運行。它必須移動該錯誤以彙總其他文件夾並在源文件夾中查找新文件。我如何讓線程繼續運行?
實際上有4個源文件夾和4個目標文件夾。我必須在每個源&目標對中執行相同的操作。所以我在一個類中創建了4個線程,在第二個類中創建了搜索操作,在第三個類中創建了文件處理。
class MainClass
{
public static void main(String[] args){
for(int i=0;i<4;i++){
SearchClass search = new SearchClass();
Thread thread = new Thread(search);
thread.start();
}
}
}
class SearchClass implements Runnable
{
public void run() {
try {
searchfile();
} catch(Exception e) {
e.printStackTrace();
}
}
public void searchfile(){
try{
ProcessClass p = new ProcessClass();
p.fileProcess();
}catch(Exception){
e.printStackTrace();
}
}
}
class ProcessClass
{
public void fileProcess(){
try{
.........................
........... ----->
// Thread1 throws exception here and get stopped.
// Its searching file in source folder again.
}catch(Exception){
e.printStackTrace();
}
}
}
請使用代碼格式化,同時發佈。在你的問題中選擇代碼段並按下Ctrl + K。 – Srikanth 2009-01-22 08:07:15