我遇到了一个问题,当我在一个类中创建一个线程(某些其他类)时,它会将该类的数组作为其构造函数的参数,并在以后的运行中更改它()函数。如何在创建线程的类中更新数组(即更新线程所做的更改)?
// public serverInit()
public connection[] myservers;
public void Threads()
{
Thread accept=new Acception(myservers);
accept.start();
}
// public class Acception extends Thread
public void run()
{
try
{
while(true)
{
client = server.accept();
if(client.isConnected())
{
for(int i=0;i<totalServers;i++)
{
String[] info=client.getInetAddress().toString().split(":");
if(info[0].compareToIgnoreCase(myservers[i].getIp())==0)
{
myservers[i].setStatus("Active");
System.out.println("Request Received From server : " +
client.getRemoteSocketAddress());
Thread work=new server(client);
work.start();
break;
}
}
}
}
}
catch(Exception e)
{
System.out.println("Connection with
"+client.getInetAddress().toString()+" failed :-(");
}
}