Some words about 1):
Implementing Runnable makes your class more flexible.
A class that implements Runnable is not a thread and just a class. For a Runnable to become a Thread, You need to create an instance of Thread and passing itself in as the target.
By extending Thread, each of your threads has a unique object associated with it, whereas implementing Runnable, many threads can share the same runnable instance.
In most cases, the Runnable interface should be used if you are only planning to override the run() method and no other Thread methods. This is important because classes should not be subclassed unless the programmer intends on modifying or enhancing the fundamental behavior of the class.
About 2)
The name of the Thread below is [myThread]
Thread myThread =new Thread(new Runnable(){
public void run(){
//code
}});
myThread.start(); //start it
About 3)
About names... If you dont care to access the Thread by name like the example above you can just a Thread and into it add code that has a behavor that you want.For example you can have a flag and making it false the Thread just finish it's work and that's it Thread finished.
new Thread(new Runnable(){
public void run(){
//example code
while(flag==true){
System.out.println("Yeah i am true ");
//Thread.sleep(200); //Makes The Thread sleep
}
}}).start(); //create and start by default
Here
public class Server{
public Server(){ //constructor
Thread client = ClientMethod("Alex");
System.out.println("i am Client "+client.getName());
}
//Make a Thread for a specific Client
public Thread ClientMethod(String clientName){
Thread client = new Thread(new Runnable(){
public void run(){
//do someWork
//Then finish
}//end of run method
});
client.setName(clientName); //set the NameOfThread to clientName
client.start(); //start it
return client; //return the Thread of this specific Client(as Object)
}
//Main Method
public static void main(String[] args){
new Server();
}
}//End of Class [Server]