Using Thread pool in Jenkins pipeline

12 views
Skip to first unread message

ramesh pasham

unread,
Dec 17, 2020, 6:40:54 AM12/17/20
to jenkins...@googlegroups.com
Anyone tried the ThreadPool in jenkins pipeline? it is not executing as expected ? Please advise.

import java.util.concurrent.*
class MyRunnable implements Runnable{
   Integer l
   MyRunnable(Integer l){
      this.l  = l
     
   }
   void run(){
   try{
    print l
     }
    catch(Exception e){
          print e
    }
  }
 
}
node{
    stage('stage1') {
        ExecutorService executor = Executors.newFixedThreadPool(6)
        mylist = 1..100
        try{  
            for(l in mylist){
                MyRunnable worker = new MyRunnable(l)
                executor.execute(worker)
        }
         }
        finally{
            executor.shutdown()
    }  
}
}
-Ramesh
Reply all
Reply to author
Forward
0 new messages