I’m trying to run a calculation in a new thread, I’m just not sure the correct way to do it. I’m not sure if I should use:
private Thread calcThread = new Thread(){
@Override
public void run(){
calc();
}
};
and then use calcThread.run() when I want to do the calculation or if I should do:
new Thread(new Runnable() {
public void run() {
calc();
}
}).start();
whenever I want to run my calculation.
Which is preferable, if either?
Thanks.
Do something like this
Just by creating object of this class like this
you can start your thread performing calculation wherever you want in the code.