Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8228977

Issue with Queue

XMLWordPrintable

    • x86_64
    • windows_10

      A DESCRIPTION OF THE PROBLEM :
      when trying to add() and poll() in two different threads at same time poll method not giving any return value also some times add method will be stops.Taking 3x times for popping compare to add.


      ---------- BEGIN SOURCE ----------
      import java.util.LinkedList;
      import java.util.Queue;


      public class Vectorr {

      static long addlong=0;
      static long polllong=0;
      Queue<Long> q = new LinkedList<>();
      public static void main(String[] args)throws Exception {
      Vectorr que=new Vectorr();

      new Thread(){
      @Override
      public void run() {
      while(true)
      {
      System.out.println("Adding to q "+addlong++);
      que.add(addlong);
                          //Thread.sleep(1);
      }
      }
      }.start();

      new Thread(){
      @Override
      public void run() {
      while(true)
      {
      polllong=que.poll();
      System.out.println("poll from q "+polllong);
                          //Thread.sleep(1);
      }
      }
      }.start();


      }

      void add(long i)
      {
      q.add(i);
      }
      Long poll()
      {
      return q.poll();
      }
      }

      ---------- END SOURCE ----------

      FREQUENCY : always


            psonal Pallavi Sonal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: