Hola tengo un ejemplo de clase , sobre multitheard, pongo la parte que no entiendo del ejemplo:
Código:
class clientThread extends Thread {
private DataInputStream is = null;
private PrintStream os = null;
private Socket clientSocket = null;
private final clientThread[] threads;
private int maxCliente;
public clientThread(Socket clientSocket, clientThread[] threads) {
this.clientSocket = clientSocket;
this.threads = threads;
maxCliente = threads.length;
}
public void run() {
int maxClientsCount = this.maxCliente;
clientThread[] threads = this.threads;
try {
is = new DataInputStream(clientSocket.getInputStream());
os = new PrintStream(clientSocket.getOutputStream());
os.println("Introduce tu nombre");
String nombre = is.readLine().trim();
os.println("Hola " + nombre + " bienvenido a la sala. Introduce /fin para salir de la sala");
for (int i = 0; i < maxCliente; i++) {
if (threads[i] != null && threads[i] != this) {
threads[i].os.println( nombre+ " se ha conectado");
}
}
solo he puesto una parte del codigo;
Código:
lo que no entiendo que es lo que hace :
public clientThread(Socket clientSocket, clientThread[] threads) {
this.clientSocket = clientSocket;
this.threads = threads;
maxCliente = threads.length;
}
tampoco:
Código:
public void run() {
int maxClientsCount = this.maxCliente;
clientThread[] threads = this.threads;
y por ultimo, en la parte del if no entiendo el this.
Código:
for (int i = 0; i < maxCliente; i++) {
if (threads[i] != null && threads[i] != this) {
threads[i].os.println( nombre+ " se ha conectado");
}
}
Agradeciria mucho que alguien pudiera resolverme estas dudas