0

어떻게 작업을 배포 할 수 있습니까? 한 파이프에서 보낸 항목을 여러 파이프로 복사하여 원본 파이프에 액세스 할 수 있습니까?하나의 스레드에서 여러 스레드로 작업을 분산하는 방법

부모 스레드가 "Pthread"라고 말하면 4,5 개의 자식 스레드에 연결하고 싶습니다. 이진 트리와 같습니다. "Pthread"에서 수행 된 모든 작업은 모든 하위 스레드 (ESB가 SOA 아키텍처에서 수행하는 것과 비슷한)에 분산되어야합니다.

One to Many in Distribution in Pipe

같이 A + B는 모두 5 개 개의 스레드에서 전송 \ 동시에 파이프 및 처리되어야한다.

이 방법이 있습니까?

답변

1
public class MainThreadEntry { 



    public void ThreadCreationMethod() 
     { 
     List<Future<Object>> listOfResult = null; // listOfResult is list of Integer objects as a result of computation by different threads 
     ExecutorService executor = Executors.newFixedThreadPool(5); // no of threads to create from main thread 
     List<EachThreadComputation> list = new ArrayList<MainThreadEntry .EachThreadComputation>(); 
     for (int i = 0; i < 5; i++) { 
      EachThreadComputation separeateComputaionInnerClass = new EachThreadComputation(1,2); // innerClass Created For Ecah Thread 1,2 parameter can be dynamic 
      list.add(separeateComputaionInnerClass); 
     } 
     try { 

      listOfResult = executor.invokeAll(list); // call on different threads with 5 separate executionpath for computation 

     } catch (InterruptedException e) { 

     } 






     } 


private class EachThreadComputation implements Callable<Object>{ 
      private int A; 
      private int B; 


      EachThreadComputation(int A,int B) { 
       this.A = A; 
       this.B = B; 

      } 


      @Override 
      public Object call() throws Exception { 
        return (Integer)A+B 

     } 
     }} 
관련 문제