0

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()

prgst
  • 121
  • 1
  • 1
  • 11
  • This is quite hard to follow with so many nondescript names. If you need something from each X instance, why not keep those instances in a separate Collection? – VGR May 29 '15 at 12:58
  • Well, my main problem is that `Z`, `X`, `Y` generally share the same function: they starts threads. So depict it: `X` is Company that has class `Boss`, `CompanyWorker` etc, 'Y` for `Consumer`, `ShopWorker`. `Z` starts `X`, `Y` but also starts class `Transport`. So the `Transport` is supposed to take things from `CompanyWorker` queue put it to transportsQueue, and then give it to `ShopWorker` queue. So passing this queues is problematic. – prgst May 29 '15 at 13:42
  • Create the queues in `Z` and pass them to the appropriate constructors... – Soana May 29 '15 at 14:08
  • But `X` ->Company is created multiple times, so each one has an id. So every time new queue should be created. So how will we take data from queue with specific id? – prgst May 29 '15 at 17:41
  • Think about where the Queues need to go. Is there one `Transport` per `Company` ? -> Give the Queue for id a to Company and Transport with id a. Do all the messages go to one `Transport`? -> put all the messages into one Queue and put the id into the message. We need more real life information to help you. Also please edit additional info into the question! – Soana Jun 01 '15 at 06:37

0 Answers0