Just I created an activity that start a new service collect some data,the this service will intiate another thread to do certain operations on the data collected by the service.....so all I feared that may the service access this array and the thread also at the same time and a race condition might happen ?
So am I thinking right or wrong ? On Thu, Jun 24, 2010 at 3:28 PM, Mark Murphy <[email protected]>wrote: > On Wed, Jun 23, 2010 at 10:46 PM, tarek attia <[email protected]> > wrote: > > Yes,I mean that,as in my service there's an array to be accessed also by > a > > thread exists in this service ,so how do I protect the array from being a > > race condition between the service and the thread? > > Comparing services and threads is like comparing apples and shoes. > > You do not "protect the array from being a race condition between the > service and the thread". > > You may wish to "protect the array from being a race condition" > between two threads. Services by default use only the main application > thread, unless you are arranging for work to be done in another thread > yourself (e.g., AsyncTask). In that case, you would want to use > java.util.concurrent classes, or the synchronization keyword, as Mr. > Boston suggests. The use of these classes is not specific to Android, > as they have been in Java for some time. > > -- > Mark Murphy (a Commons Guy) > http://commonsware.com | http://github.com/commonsguy > http://commonsware.com/blog | http://twitter.com/commonsguy > > _The Busy Coder's Guide to *Advanced* Android Development_ Version 1.6 > Available! > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected]<android-developers%[email protected]> > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- tarek -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

