consider the following scenario
i have class1 which is creating a instance of a
thread but i need to start the thread in another class say in class2
class class1
{
public void mthd1()
{
myRunnable runable = new myRunnable();
Thread t = new Thread(runable);
.
.
new class2(this);
}
.
.
}
class class2()
{
public mthd2()
{
// need to start thread t here
}
}
To start the thread here i need to pass the reference to class2 either in these two way
1. put a getter method in class1 which returns "t" (since class2 has reference to class1) invoke this getter method
2. pass the reference while creating the class2 object
i dont feel both the ways are best practices
is there any better ways to do this?