線程我需要知道Java線程的陣列。這裏是C#陣列在Java中
Thread[] TCreate = new Thread[iThreadSize];
for (int i = 0; i < 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<TCreate.Length;j++)
while (TCreate[j].IsAlive)
Thread.Sleep(10);
我需要知道要做到這一點在Java線程的陣列碼。
MyTestClass qryCompoents=new MyTestClass();
for(int i=0;i<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;
}
}
讓我知道你是否需要任何細節。
如果我轉換此
Thread[] TCreate = new Thread[numExpression];
for(int i=0;i<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 < TCreate.length; j++)
while (TCreate[j].isAlive())
Thread.sleep(5);
顯示錯誤:無法指非最終變量「OBJ」在不同的方法中定義的內部類內部
由於事先
任何人都可以幫我.. –
'obj'的聲明是怎麼樣的? (我更新了我的答案) – dacwe