title: Accesing static variable from another class in java
body: <p>I had a queue implemented as linked list in my multithreaded server. I want to access this queue from another class. Both classes are in the same package. I tried making this queue as public static and accessing it through getter, but without success Can somebody tell me what is the exact problem. </p>
  
  <p>This is my code:
  Queue Declaration:</p>
  
  <pre><code>public static Queue&lt;Request&gt; q=new ConcurrentLinkedQueue&lt;Request&gt;();
  
  public static void setQ(Queue&lt;Request&gt; q) {
          Connection.q = q;
      }
  
      public static Queue&lt;Request&gt; getQ() {
          return q;
      }
  </code></pre>
  
  <p>Accesing Queue:</p>
  
  <pre><code>Queue&lt;Request&gt; queue=new ConcurrentLinkedQueue&lt;Request&gt;(); 
  queue=Connection.getQ();
  </code></pre>
  
  <p>Adding Value to Queue in thread of connection</p>
  
  <pre><code>q.add(r);
  </code></pre>