I would like to start a thread and pass in an object which I create somewhere bu开发者_开发技巧t want to set its values from within the thread.
How is this achieved?
Thanks
Just pass it when you construct the Thread
(or preferably, Runnable
):
public class Task implements Runnable {
private YourObject yourObject;
public Task(YourObject yourObject) {
this.yourObject = yourObject;
}
@Override
public void run() {
yourObject.setSomething("something"); // See?
}
}
精彩评论