运行线程的对象如何与包含类进行通信?

时间:2016-03-09 14:15:30

标签: multithreading user-interface javafx thread-safety

Class Person()
{
Eyes eyes;

Person(){
eyes = new Eyes();
eyes.watching();
}

Thread updateGUI(){
//want to safely  report what's being seen
}

}


Class Eyes()
{
String whatIsee;

public void watching()
{
    Task task = new Task()
    {
        while(1)
        {
        whatIsee = look();
        //then send what I see back to Person
        }
    }
}
}

我可以传递一个" whatIHaveSeen"进入Eyes构造函数。这样做。我知道需要做一些工作来保证线程安全。我只是想要并理解如何去做。

0 个答案:

没有答案