我正在为圣经编写一个文本搜索程序,我想使用线程来划分工作,以减少执行时间。我对 Java 编程比较熟悉,但对整个“线程”来说是全新的。基本上,该程序是拉出单独的圣经书卷,阅读文本,搜索单词,然后拉入下一本书。我想把它分开,以便 4-8 个线程在不同的书上同时工作。
有什么帮助吗?
public static void main(String args[]){
String wordToSearch = "";
String[] booksOfBible;
int bookPosition = 0;
ArrayList<String> finalList = new ArrayList<String>();
getWord gW = new getWord();
getBook gB = new getBook();
checkBook cB = new checkBook();
wordToSearch = gW.getWord(wordToSearch);
booksOfBible = gB.getFileList();
//System.out.println(wordToSearch);
for(int i = 0; i < booksOfBible.length; i++){
//System.out.println(booksOfBible[i]);//Test to see if books are in order
String[] verses = gB.getNextBook(booksOfBible, bookPosition);
//System.out.println(verses[0]);//Test to see if the books are being read properly
cB.checkForWord(wordToSearch, verses, booksOfBible[i], finalList);
bookPosition++;
}
for(int i = 0; i < finalList.size(); i++){
System.out.println(finalList.get(i));
}
System.out.println("Word found " + finalList.size() + " times");
}