title: Creating many different threads in a for loop only producing one thread (java)
body: <p>I'm trying to spin up many threads in a Producer-Consumer model in Java and for some reason it's not doing what it's supposed to. </p>
  
  <p>I have code that does </p>
  
  <pre><code>List&lt;Thread&gt; consumers = new ArrayList&lt;&gt;();
              for (int i = 0; i &lt; noOfThreads; i++) {
  
                  Thread consumer = new Thread(new Runnable() {
  
                      String name = "Thread-" + UUID.randomUUID();
                      @Override
                      public void run() {
                          try {
                              pc.consume(name);
                          } catch (InterruptedException e) {
                              e.printStackTrace();
                          }
                      }
                  });
                  consumers.add(consumer);
                  consumer.start();
                  consumer.join();
              }
  </code></pre>
  
  <p>where <code>pc</code> is a ProducerConsumer whose consume method is</p>
  
  <pre><code> public void consume(String name) throws InterruptedException {
              while (true) {
                  synchronized (this) {
                      while (subQueue.size() == 0) {
                          wait(2000);
                      }
                      Subscriber sub = subQueue.poll();
  
                       System.out.println(name);
  
                      uploadEndpointToPinpoint(sub);
                      notify();
                  }
              }
          }
  </code></pre>
  
  <p>So, when I run this I expect to see it print out 10 different UUIDs, indicating that there are 10 threads running - but that's not happening. Instead I just get:</p>
  
  <pre><code>Thread-c42ac697-d4ad-4944-a20e-907952f5d5ab
  Thread-c42ac697-d4ad-4944-a20e-907952f5d5ab
  Thread-c42ac697-d4ad-4944-a20e-907952f5d5ab
  Thread-c42ac697-d4ad-4944-a20e-907952f5d5ab
  Thread-c42ac697-d4ad-4944-a20e-907952f5d5ab
  Thread-c42ac697-d4ad-4944-a20e-907952f5d5ab
  Thread-c42ac697-d4ad-4944-a20e-907952f5d5ab
  </code></pre>
  
  <p>which means that it only started one of the threads. Why is the for loop not doing what I think it should?</p>
  
  <p>Any and all help would be appreciated.</p>