Java simplify code
<p>i have a beginners question:</p>

<p>I have 3 Classes extending Thread. They are doing the same job: open a ServerSocket and then wait for connections in a while loop. The only difference between these classes is, that they start a specific Thread when they have a connection.
I want to simplify this and have one Class doing the job, that atm 3 classes are doing. In the example the only difference is the call of SocketThread1, SocketThread2 and SocketThread3.</p>

<p>How could i make 1 class instead of having 3 of them?</p>

<p>Example:</p>

<pre><code>\\class 1

public void run()
{
    while(true)
    {
        Socket s = serversocket.accept();
        new SocketThread1(s).start();
    }}

\\class 2

public void run()
{
    while(true)
    {
        Socket s = serversocket.accept();
        new SocketThread2(s).start();
    }


}

\\class 3

public void run()
{
    while(true)
    {
        Socket s = serversocket.accept();
        new SocketThread3(s).start();
    }
</code></pre>
