I have created two patterns: one which starts class X
(which contains thread started with ExecutorService
, name it Es), second one starts class Y
(which also contains thread started with ES
). Now, both of them are started inside class Z
with Es
. However, Z
also starts group of threads (ES
again) directly from itself.
public class Z {
...
public static void main(String [] args)
{
service=Executors.newFixedThreadPool(xNum);
for(int k=0; k < xNum; k++){
X x=new X(k);
service.submit(x);
}
service=Executors.newFixedThreadPool(yNum);
for(int k=0; k < yNum; k++){
Y y=new Y(k);
service.submit(y);
}
service=Executors.newFixedThreadPool(zNum);
for(int k=0; k < zNum; k++){
directThread dt=new directThread(queue1, queue2, queue3);
service.submit(dt);
}
}
}
Inside class X there are many threads, but one interests me particularly":
public class X{
...
public void run(){
while(true){
...
service = Executors.newFixedThreadPool(XStuffNum);
for (int i=0; i < SStuffNum; i++) {
service.submit(new FirstClass(blocking1, blocking2, blocking3));
}
}
}
}
cognately in Y
class there is SecondClass
.
queue and blocking are names for BlockingQueues.
So dt
is supposed to take data from FirstClass
blocking, put them inside its queues, and then pass them to SecondClass
queues. My question is, how to let dt
take queues that are inside FirsClass
?
EDIT. Problem solved. It is enough to create getters inside X
and Z
so Y
can do X.getQueue().operation()