title: Jenkins pipeline script - Thread programming
body: <p>I am trying to create multiple threads in a jenkins pipeline script. So, I took simple example as below. But it not working. Could you please let me know?</p>
  
  <p>In the below example, jobMap contains a key as a string and value as List of Strings. When I just display the list, the values printed properly, but when I used 3 different ways to create threads and thus to display, it is not working.</p>
  
  <pre><code>for ( item in jobMap ) 
      {           
          def jobList = jobMap.get(item.key);
  
          **// The following loop is printing the values**
          for (jobb in jobList) 
          {
                   echo "${jobb}"
          }
  </code></pre>
  
  <blockquote>
    <p><strong>// Thread Implementation1:</strong></p>
  </blockquote>
  
  <pre><code>        Thread.start 
          {
  
                  for (jobb in jobList) 
                  {
                   echo "${jobb}"
                  }
  
          }
  </code></pre>
  
  <blockquote>
    <p><strong>// Thread Implementation2:</strong></p>
  </blockquote>
  
  <pre><code>        def t = new Thread({ echo 'hello' } as Runnable)
          t.start() ;
          t.join();
  </code></pre>
  
  <blockquote>
    <p><strong>// Thread Implementation3:</strong></p>
  </blockquote>
  
  <pre><code>        t1 = new Thread( new TestMultiThreadSleep(jobList));
          t1.start();         
      }
  
  
  
      class TestMultiThreadSleep implements Runnable {
     String jobs;
     public TestMultiThreadSleep(List jobs) {
        this.jobs = jobs;
     }
  
  
  
       @Override
         public void run() 
  {
         echo "coming here"
           for (jobb in jobs) 
              {
                   echo "${jobb}"
              }                      
         }
      }
  </code></pre>