I am writing an application for Android and am using worker threads to process certain information. Having read through my code I am now unsure if it is thread safe.
I have written a simplified version of my code, I have omitted the Handler
object used to communicate with the main thread and obviously the process itself.
public class myClass implements Runnable
{
private String myString;
@Override
public void run()
{
myString = "Some Value";
}
}
This is called by running something similar to this.
myClass class = new myClass();
Thread thread = new Thread(class);
thread.start()
So, is this code not thread safe because I am modifying myString
(declared in the main thread) in the run()
function?