title: How to approach a producer-consumer solution using threads in springboot
body: <p>I have gone through some <code>Spring</code> <a href="https://www.baeldung.com/thread-pool-java-and-guava" rel="nofollow noreferrer">documentation</a> to find out how i can simulate the producer-consumer solution, and I've found out that <code>Spring</code> can handle <code>Threads</code> like so:</p>
  <p><a href="https://i.stack.imgur.com/CHt8R.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CHt8R.jpg" alt="enter image description here" /></a></p>
  <p>Things start to get confusing when i'd like to make this kind of call <code>Asyncronous</code> and <code>notify</code> all consumers.</p>
  <hr />
  <h2>My approach so far without Threads</h2>
  <p>I've got a <code>@Controller</code> where i make a <code>Synchronous</code> call to my <code>database</code> to grab all the data i need.</p>
  <pre class="lang-java prettyprint-override"><code>@GetMapping(&quot;/manageEvents&quot;)
  public String getManage(Model model, HttpServletResponse response) {
   List &lt; Event &gt; events = eventsRepo.findAll();
   model.add(&quot;events&quot;,events);
   return &quot;manageEvents&quot;
  }
  </code></pre>
  <p>The <code>manageEvents.html</code> contains an <code>Ajax</code> call to an endpoint to get all <strong>new</strong> <code>Events</code> ,so in case there is a new one , i'm showing it as a <code>pop-up</code> to the current logged-in <code>User</code> through <code>JavaScript</code>.</p>
  <hr />
  <h2>Goal</h2>
  <p>As you may have thought, my goal is this <strong>new</strong> <code>Event</code> to be added to the <code>Thread Pool</code> and immediately show it in my <code>html</code> as a <code>pop-up</code> and who ever grabs it first, can manage it (like a task assignment).</p>
  <blockquote>
  <p>Spring also provides an <a href="https://www.baeldung.com/spring-async" rel="nofollow noreferrer">Async</a> annotation which i can use.</p>
  </blockquote>
  <hr />
  <p>How can i approach this solution by using Threads?</p>