I have a class, “myClass” with this code in the “main”:
ExecutorService service;
List<Future<Integer>> tasks = new ArrayList<Future<Integer>>();
service = Executors.newFixedThreadPool(numOfThreads);
Then I initiate each thread:
for (int i = numOfThreads; i > 0; --i) {
tasks.add(service.submit(new StringSearcher(file, offset,threadChankSize, args[1],buffSize)));
}
for (Future<Integer> task : tasks) {
result += task.get();
}
The class has “_res” member that I need to get at the end of the program (after all threads terminated)
In order to do that I created a method “getRes” which returns “_res”, but the problem is I don’t have access to the class after it’s thread has terminated.
is there a way to keep reference from “main” to the instance created in each thread?
You could just do this: