Your code is very complicated - you extend Thread
, implement Runnable
internally and within the Runnable
create another Thread
. That's not correct approach.
Interface Runnable
can be considered as a command design pattern - it's a unit of work to be done and it has been designed to separate logic of "what have to be done" from the threading mechanisms.
I don't know if I get your problem correctly, but from what I understand, you just try to pass some parameters to the callback being run in separate thread. So why don't just introduce some class implementing Runnable
(that's your unit of work to be done) and pass by constructor some work parameters. What I mean is something like below:
public class MyUnitOfWork implements Runnable {
private final Data data;
public MyUnitOfWork(final Data data) {
this.data = data;
}
public void run() {
// do something with data
}
}
and later on:
Thread t = new Thread(new Data(/* something */));
t.start();