创建
mylookupThread单独的类,使其成为实例并将其传递给
Executor:
class LookupTask implements Runnable { private final String filePath, searchIndex; LookupTask(String filePath, String searchIndex) { this.filePath = filePath; this.searchIndex = searchIndex; } public void run() { ... } }...background.execute(new LookupTask(filePath, searchIndex));另一种方法是使
filePath, searchIndex最终:
final String filePath = ...final String searchIndex = ...Executor background = Executors.newSingleThreadExecutor();Runnable mylookupThread = new Runnable() { public void run() { MainWindow.this.processFile(filePath); Thread t = new Thread(new lookupThread(MainWindow.arrFile, true, false, searchIndex)); t.setName("Lookup"); t.setPriority(10); t.start(); }};background.execute(mylookupThread);


