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构造函数。这样做。我知道需要做一些工作来保证线程安全。我只是想要并理解如何去做。