Thread and Runnable passage of objects

Hi all,

I'm having a lit of trouble to put this working, I have a class responsible for the network communication of my program.

It has to accept incoming request and deal with them properly.

For that I have the following code:

publicvoid receive(){

System.out.println("Receive start");

// Server

Runnable srv =new Runnable(){

publicvoid run(){

Socket s;

try{

while (true){

ss =new ServerSocket(7000);

System.out.println("Waiting for incoming connections ...");

s=ss.accept();

//Takes care of the accepted calls

Runnable cli =new Runnable(){

private Socket soc;

publicvoid run(){

System.out.println("Client " + soc.getInetAddress().toString() +"Connected");

}

};

Thread c =new Thread(cli);

c.run();

}

}catch(Exception err){

System.out.println("Burn to the ground");

};

}

};

Thread r =new Thread(srv,"srv");

r.run();

System.out.println("Receive end");

}

If I try to use the same var it states it needs to be final, I'm unable to create method to put into there.

Is it the best way the create a second class extending thread?

Thanks to all

Alex

[2468 byte] By [EtherealSoula] at [2007-11-27 5:30:24]
# 1
Use a class variable and not a method local variable.
_dnoyeBa at 2007-7-12 14:54:30 > top of Java-index,Core,Core APIs...
# 2
call start() not run()
cooper6a at 2007-7-12 14:54:30 > top of Java-index,Core,Core APIs...
# 3
Hi,> Is it the best way the create a second class extending thread?I would recommend to extend Runable.BTW, You need to call start() to make new Thread to be executed separatly ;)Good luck!
_Dima_a at 2007-7-12 14:54:30 > top of Java-index,Core,Core APIs...