There's nothing wrong with subclassing Thread, as you suggest.
You can make use of some anonymous inner class magic, if you prefer. This allows you to implement Runnable, rather than subclassing Thread, while still providing arguments to the Runnable.
The advantage of implementing Runnable, rather than subclassing Thread, is that you can implement Runnable (and other interfaces, if you want) while subclassing something else of your choosing. This is because of the single inheritance of
Java.
Example of anonymous inner class for Runnable:
<code>
/** Any method within any class of your choosing.
* @param param1 a value to be passed to the Runnable
*/
public void doSomething(final int param1)
{
// another value to be passed to the Runnable
final
String param2 = getSomeData();
// Construct a Runnable using anonymous inner class
Runnable task = new Runnable()
{
public void run()
{
// do something with the values passed in
performOperation(param1, param2);
}
};
Thread taskThread = new Thread(task);
taskThread.start();
}
</code>
The values param1 and param2 are declared as final, and this is a requirement. Behind the scenes, the Java compiler creates a class file for the anonymous inner class here. That created class includes data and methods for access of the param1 and param2 values.