A question on design...
I have a program that runs 3 threads
1) The main thread. (MyProg.java)
2) Some reader threads. (Reader.java)
3) Some worker threads. (Worker.java)
The main thread starts the Reader and Worker threads. Does some work on its own. Waits for Reader and Worker threads to complete and then does some more work.
Now I have lots of global variables (most of themfinal , say around 10) that need to be used by all 3 threads. Synchronized access is /not/ required because no one is going to change them once they are set by main.
Also I have some general methods which will be called from all 3 threads. So I have them as static methods in MyProg. (Assume synchronized access is not required)
Class MyProg{
privatestaticfinalint x = 1;
privatestaticfinalint y = 2;
privatestaticfinalint z = 3;
privatestaticint a;
privatestaticint b;
privatestaticint c;
/*
* A few more variables
*/
publicstaticvoid main (String args[]){
// set the value of a,b,c depending on args[]
// start reader and worker threads
// do some work
// wait for reader and worker threads to join
// do some more work
}
publicstatic method1(){
}
publicstatic method2(){
}
}
class Reader{
publicvoid run (){
/*
* use the global variables as follow...
*/
int a = MyProg.getA();
/*
* call the general methods as follows ..
*/
MyProg.method1();
MyProg.method2();
}
}
1) Is this a good idea to have all these static variables and methods in the class which has the main thread running.
2) Or should main() creante an instance of MyProg and send a reference to Reader and Writer ?
3) Or should I remove all the global variables/methods from MyProg and have them in a fourth class. Then main() can create an object of this 4th class and pass it on to the Reader and Worker threads ? (Or perhaps implement the 4th class as a singleton)
The problem with this approach is that I cannot think of a name for the 4th class. I could use MyProg for it but then what should I name the class which has main ?
4) Or should I use some other approach ?

