I've been struggling with this for 7 days now. Your insights will be greatly appreciated.
Consider the framework code.
final class Main {
// assuming programmerCode was injected
Interface inter = (Interface) programmerCode;
inter.doProcess();
}
interface Interface {
void doProcess();
}
abstract ProgramApp implements Interface {
public void doProcess() {
for (File file : files) {
foo(file);
bar(file);
}
}
public abstract void foo(File file);
public abstract void bar(File file);
}
abstract Program extends ProgramApp {
public final void doProcess() { }
}
and the code using it,
class ProgrammerCode extends Program {
File file;
String a1;
String a2;
public void foo(File file) {
// read file per line store in a1
}
public void bar(File file) {
// read file per line and append somestring and store in a2
}
}
Right now, this program processes files in series. Any suggestion on how to make this program process files in parallel without touching the ProgrammerCode?
Aim: Each file should be processed independently in parallel using the implementation of the methods in ProgrammerCode without modifying it. The modification should be done somewhere in the framework code.
I really have no idea where to put the threading part here. My assumption is it should be in the file loop but I don't know if it's thread-safe since I'll be using the methods defined in the ProgrammerCode.