2013-03-27 1 views
1

저는 디렉토리에있는 모든 파일을 가져와 5 개의 파일을 병렬로 실행하고 다음 5 개의 파일 만 다시 실행합니다. 이미 실행 된 파일은 다시 실행하면 안됩니다.디렉토리에서 파일을 가져 와서 한 번에 5 개씩 병렬로 실행하는 방법

<target name="ParallelTest" description="Checking the parallelTest"> 
     <for param="file" > 
      <path> 
       <fileset dir="C:/RCBuild3/ofs/bin/prd1"> 
         <include name="*.xml"/> 
       </fileset> 
      </path> 
      <sequential> 
       <antcall target="parallelexecutoin"> 
        <param name="productfile" value="@{file}"/> 
       </antcall> 
      </sequential> 
     </for> 

    </target> 
    <target name="parallelexecutoin"> 
     <exec dir="C:/RCBuild3/ofs/bin/" executable="cmd"> 
      <arg value="/c"/> 
      <arg value="productupload.bat"/> 
      <arg value="-fileName"/> 
      <arg value="${productfile}"/> 
     </exec> 
    </target>  

위의 코드는 순차적으로 실행됩니다. 첫째

답변

2

코드 :

<fileset dir="C:/RCBuild3/ofs/bin/prd1" id="src.files"> 
    <include name="*.xml"/> 
</fileset> 

<pathconvert pathsep="," property="file.list" refid="src.files"/> 

<for list="${file.list}" delimiter="," param="file" parallel="true" threadCount="5"> 
    <sequential> 
     <antcall target="parallelexecutoin"> 
      <param name="productfile" value="@{file}"/> 
     </antcall> 
    </sequential> 
</for> 

는 설명 : 모든

먼저, 처리 할 필요가있는 모든 파일에 대해 fileset을 준비합니다.

그런 다음 pathconvert을 사용하여 파일 세트를 filename1.xml,filename2.xml,filename3.xml과 같은 "file.list"속성으로 변환하십시오. (당신의 개미 파일 뒤에 숨 깁니다)

for 작업의 자바 코드는 List을 통해 List에 쉼표를 사용하여 "file.list"및 루프를 분할합니다. List의 각 요소에 대해 루프 본문 (sequential 부분)이 실행됩니다.

parallel은 복수 스레드로 루프 본문을 실행하는 작업을 말하며, 동시에 실행될 수있는 최대 스레드 수는 threadcount입니다.

따라서 parallel = truethreadcount = 5은 정확히 5 파일 씩 설명하는대로 작동합니다.

관련 문제