首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何通过线程访问Runnable对象?

如何通过线程访问Runnable对象?
EN

Stack Overflow用户
提问于 2010-02-20 08:47:11
回答 11查看 48.2K关注 0票数 26

可能的重复项:need-help-returning-object-in-thread-run-method

你好。我有一个实现runnable的类,我有一个List,存储用该类的不同对象实例化的Thread。给定运行底层对象的线程对象,我如何访问它们的属性?下面是一个示例:

代码语言:javascript
复制
public class SO {
    public static class TestRunnable implements Runnable {
        public String foo = "hello";

        public void run() {
            foo = "world";
        }
    }

    public static void main(String[] args) {
        Thread t = new Thread(new TestRunnable());
        t.start();
        //How can I get the value of `foo` here?
    }
}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2300579

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档