title: Values not being passed properly in a linked blocking queue
body: <p>How this works is my can will enter the belt and then will be scanned with the sterilize class, but I have problems as such that my cans are not being passed properly, meaning that some of my cans are not being scanned, eg: Once can 1 is scanned, it says can 2 is added into the belt, but it skips to can 3 straight away </p>
  
  <pre><code>public class AsiaPacificFruitFactory {
  
  
  public static void main(String[] args) {
      LinkedBlockingQueue&lt;Can&gt;beltQ = new LinkedBlockingQueue&lt;Can&gt;();
      LinkedBlockingQueue&lt;Can&gt;sterilizeQ = new LinkedBlockingQueue&lt;Can&gt;();
  
      Belt b = new Belt(beltQ);
      Sterilize s = new Sterilize(beltQ, sterilizeQ);
      b.start();
      s.start();
  }
  
  }
  
     class Belt extends Thread{
          LinkedBlockingQueue&lt;Can&gt;beltQ;
  
      public Belt (LinkedBlockingQueue&lt;Can&gt; beltQ){
          this.beltQ = beltQ;
      }
      @Override
      public void run(){
          while(true){
              addCan();
              try{
                  Thread.sleep(500);
              }catch (Exception e){}
          }
      }
  
      public void addCan(){
          for (int i=1; i&lt;501; i++){
              try{
                  beltQ.put(new Can(i));
                  System.out.println("Can " + i + " has been added into the belt" );
                  Thread.sleep(500);
              }catch (Exception e){}
          }
      }
  }
  
  class Scanner implements Callable&lt;Can&gt;{  
      Can c;
  
      public Scanner (Can c){
          this.c = c;
      }
  
      Random rand = new Random();
  
      public Can call() throws Exception{
          System.out.println("Scanning can " + c.CanNo + " for dents");
          c.getDefect();
  
          if(c.defect == 3){
              System.out.println("Can " + c.CanNo + " is dented");
              return null;
          }
          else{
              System.out.println("Can " + c.CanNo + " is not dented");
              return c;
          }
      }
  }
  
  class Sterilize extends Thread{
      LinkedBlockingQueue&lt;Can&gt;beltQ;
      LinkedBlockingQueue&lt;Can&gt;sterilizeQ;
  
      public Sterilize (LinkedBlockingQueue&lt;Can&gt; beltQ, LinkedBlockingQueue&lt;Can&gt;sterilizeQ){
          this.beltQ = beltQ;
          this.sterilizeQ = sterilizeQ;
      }
  
  
      public void run(){
          while(true){
              try{
                  Can c = beltQ.take();
                  ExecutorService exe = Executors.newCachedThreadPool();
                  Future&lt;Can&gt; tempCan = exe.submit(new Scanner(c));
                  if(tempCan.get() == null){
                      System.out.println("Can " + c.CanNo + " has not passed the scanning section");
                      continue;
                  }else{
                      sterilizeQ.put(beltQ.take());
                  }
              exe.shutdown();
              }catch(Exception e){}
          }
      }
  }
  </code></pre>
  
  <p>My output is like this:</p>
  
  <pre><code>Can 1 has been added into the belt
  Scanning can 1 for dents
  Can 1 is not dented
  Can 2 has been added into the belt
           Can 1 has passed scanning......proceeding with sterilizing now
  Can 3 has been added into the belt
  Scanning can 3 for dents
  Can 3 is not dented
  Can 4 has been added into the belt
           Can 3 has passed scanning......proceeding with sterilizing now
  </code></pre>