title: Array of threads in java
body: <p>I need to know array of thread in java .Here is code for array of thread in C#</p>
  
  <pre><code>  Thread[] TCreate = new Thread[iThreadSize];
          for (int i = 0; i &lt; TCreate.Length; i++)
          {
              TCreate[i] = new Thread(delegate()
                  {
                      lst.Add(this.getResult(url));
                  });
              TCreate[i].Name = "URL"+i;
              TCreate[i].Start();
  
          }
          for(int j=0;j&lt;TCreate.Length;j++)
              while (TCreate[j].IsAlive)
              Thread.Sleep(10);
  </code></pre>
  
  <p>I need to know to do this in java . </p>
  
  <pre><code>MyTestClass qryCompoents=new MyTestClass();
  for(int i=0;i&lt;ThreadSize;i++)
          {
  
              switch(obj.getQueryLevelValue(i))  //Decide according to level
              {
              case 1:
                      qryCompoents.prepareAndProcess_I(obj.getQueryString(i),obj,i);
                      break;
              case 2:
                      qryCompoents.prepareAndProcess_II(obj.getQueryString(i),obj,i);
                      break;
  
              }               
  
          }
  </code></pre>
  
  <p>let me know if you need any details. </p>
  
  <p>if i convert this </p>
  
  <pre><code>    Thread[] TCreate = new Thread[numExpression];
  
          for(int i=0;i&lt;numExpression;i++)
          {
               TCreate[i] = new Thread(new Runnable() {
                      public void run() {
                          switch(obj.getQueryLevelValue(i))  //Decide according to level
                          {
                          case 1:
                                  qryCompoents.prepareAndProcess_I(obj.getQueryString(i),obj,i);
                                  break;
                          case 2:
                                  qryCompoents.prepareAndProcess_II(obj.getQueryString(i),obj,i);
                                  break;
  
                          }           
                      }
                  });
                  TCreate[i].setName("URL"+i);
                  TCreate[i].start();         
          }
            for (int j = 0; j &lt; TCreate.length; j++)
                  while (TCreate[j].isAlive())
                       Thread.sleep(5);
  </code></pre>
  
  <p><strong>Showing Error : Cannot refer to a non-final variable "obj" inside an inner class defined in a different method</strong></p>
  
  <p>thanks in Advance</p>