title: Producer and Consumer shared queue with values coming from HttpRequest
body: <p>This is the classic problem of Producer/Consumer. I start both threads when I bootstrap my Spring Boot application. I just want to write from Producer thread into the shared queue when I receive a httpRequest. So, how can I pass this value to my Producer thread in order that I can put it in the shared queue?. Is it possible?</p>
  
  <p><strong>Main Class</strong></p>
  
  <pre><code>public class ProducerConsumerPattern {
      public static void main(String args[]) {
  
          // create shared object
          BlockingQueue sharedQueue = new LinkedBlockingQueue();
  
          // create Producer and Consumer Thread
          Thread prodThread = new Thread(new Producer(sharedQueue));
          Thread consThread = new Thread(new Consumer(sharedQueue));
  
          // start producer and Consumer thread
          prodThread.start();
          consThread.start();
      }
  }
  </code></pre>
  
  <p><strong>Consumer Class</strong></p>
  
  <pre><code>class Consumer implements Runnable {
      private final BlockingQueue sharedQueue;
  
      public Consumer (BlockingQueue sharedQueue) {
          this.sharedQueue = sharedQueue;
      }
  
      @Override
      public void run() {
          while(true) {
              try {
                  System.out.println("Consumed: "+ sharedQueue.take());
              } catch (InterruptedException ex) {
                  Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, ex);
              }
          }
      }
  }
  </code></pre>
  
  <p><strong>Producer Class</strong></p>
  
  <pre><code>class Producer implements Runnable {
      private final BlockingQueue sharedQueue;
  
      public Producer(BlockingQueue sharedQueue) {
          this.sharedQueue = sharedQueue;
      }
  
      @Override
      public void run() {
          // I don't want to write in the queue the counter values.
          // I want to put my own values, when I receive them from outside **
          for (int i=0; i&lt;10; i++) {
              try {
                  System.out.println("Produced: " + i);
                  sharedQueue.put(i);
              } catch (InterruptedException ex) {
                  Logger.getLogger(Producer.class.getName()).log(Level.SEVERE, null, ex);
              }
          }
      }
  }
  </code></pre>
  
  <p>I can get the http param through <code>@RestController</code> and <code>@RequestMapping</code>, but how can I get Producer thread and put this new value into the queue?</p>
  
  <p>Thanks in advance!</p>