我正在为Android编写一个应用程序,并且正在使用工作线程来处理某些信息。通读我的代码后,我现在不确定它是否是线程安全的。此线程安全吗?
我已经写了我的代码的简化版本,我省略了用于与主线程进行通信的Handler
对象,显然还有进程本身。
public class myClass implements Runnable
{
private String myString;
@Override
public void run()
{
myString = "Some Value";
}
}
这是通过运行类似于此的调用。
myClass class = new myClass();
Thread thread = new Thread(class);
thread.start()
那么,这个代码不是因为我在run()
功能修改myString
(在主线程声明)是线程安全的?
你的问题让我想起了很多这篇文章http://blogs.msdn.com/b/ericlippert/archive/2009/10/19/what-is-this-thing-you-call-thread-safe。 ASPX – 2010-09-10 17:03:34