I have a class with a bunch of methods in. for instance
private int forFunction(String exceptionFileList, FileInfo z, String compltetedFileList, String sourceDir) { atPDFNumber++; exceptionFileList = ""; int blankImage = 1; int pagesMissing = 0;
Now what I'm trying to do now is access this class in a thread .. but not only one thread, maybe about 5 threads to speed up processing, since one of them is a bit slow.
Now, in my opinion, this will be chaos ... I mean one thread that changes variables, while another thread is busy with them, etc. etc. and blocks every variable in all of these methods ... not going to have a good time ...
So I suggest and donβt know if this is right ... this
public void MyProc() { if (this method is open, 4 other threads must wait) { mymethod(var,var); } if (this method is open, 4 other threads must wait and done with first method) { mymethod2(); } if (this method is open, 4 other threads must wait and done with first and second method) { mymethod3(); } if (this method is open, 4 other threads must wait and done with first and second and third method) { mymethod4(); } }
Would this be the right way to approach the problem of multiple threads accessing multiple methods at the same time?
These threads will have access only to the class 5 times, and no more, since the workload will be divided equally.
source share