Jun 23 | 7:20 PM |
Mark M. | has entered the room |
Jun 23 | 7:25 PM |
Mark M. | turned on guest access |
Scott P. | has entered the room |
Mark M. |
howdy, Scott!
|
Scott P. |
Hello Mark
|
Scott P. |
Haven't quite got rid of me yet
|
Scott P. |
questions about threading for you today
|
Mark M. |
fire away
|
Scott P. |
Alright, so I need to send something to a server
|
Scott P. |
so obviously I want to do that in an async task
|
Jun 23 | 7:30 PM |
Mark M. |
or an IntentService, but certainly in a non-main-application thread
|
Scott P. |
I'm currently doing this inside of a service
|
Scott P. |
I'm using one of Googles new methods for connecting with app engine
|
Scott P. |
and it doesn't seem to support concurrency
|
Scott P. |
and I end up needing to send multiple things
|
Scott P. |
so while one is still sending, I end up with another that needs to be sent
|
Scott P. |
how would you recommend I do this?
|
Scott P. |
I was thinking I would probably use a blocking queue
|
Scott P. |
but I'm really not that familiar with concurrency
|
Mark M. |
two questions:
|
Mark M. |
1. what is making the decision that something needs to be sent? an activity? a service?
|
Mark M. |
2. what happens to your service when there is nothing more to be sent?
|
Scott P. |
1. the Service
|
Scott P. |
2. It stays open. OnStartCommand returns Service.START_STICKY;
|
Mark M. |
then I'd dump the AsyncTask (you're presumably not using onPostExecute() anyway) and use a thread with a LinkedBlockingQueue
|
Scott P. |
ok
|
Jun 23 | 7:35 PM |
Scott P. |
how do I implement a thread? I tried for something simple once, but it kinda failed, so I dumped it and went back to AsyncTask
|
Mark M. |
you'll see an example of this in the AdvServices/RemoteServiceEx project
|
Scott P. |
ok
|
Mark M. |
I use a thread and LinkedBlockingQueue to asynchronously handle requests from a client over a remote service binding
|
Mark M. |
this is covered in the Advanced Services chapter of _The Busy Coder's Guide to Advanced Android Development)
|
Scott P. |
ok
|
Scott P. |
let me load up that project real fast
|
Mark M. |
to actually run it, you'd also need AdvServices/RemoteClientEx
|
Mark M. |
since it's a remote service sample
|
Scott P. |
hey
|
Scott P. |
what is the difference between the Google API's and the Android X.X for the build targets
|
Jun 23 | 7:40 PM |
Mark M. |
Google APIs have Google Maps
|
Scott P. |
is that the only difference?
|
Mark M. |
AFAIK, yes
|
Scott P. |
so unless I want to use google maps I should just use the sdk
|
Scott P. |
?
|
Mark M. |
not necessarily
|
Mark M. |
for an AVD, I'd use the Maps one, because devices will have Maps
|
Mark M. |
(at least in general)
|
Mark M. |
for a build target, stick with the plain SDK unless you're using Maps, though
|
Scott P. |
AVD?
|
Mark M. |
emulator image
|
Mark M. | |
Jun 23 | 7:50 PM |
Scott P. |
hmmm
|
Scott P. |
so it looks like the thread is paused here
|
Scott P. |
Job j=q.take();
|
Mark M. |
correct
|
Mark M. |
take() is a blocking call
|
Scott P. |
and that's ok?
|
Scott P. |
it's ok to just have a paused thread... all the time?
|
Mark M. |
that's kinda the point
|
Mark M. |
if there is nothing to do, you want the thread to consume no CPU time
|
Mark M. |
so, you block
|
Mark M. |
now, you wouldn't call take() on the main application thread, because that thread has work to do
|
Scott P. |
i just thought it was a waste to have a thread taken and paused the entire time
|
Scott P. |
I wasn't sure what that would do
|
Scott P. |
but that won't have a negetive performance impact at all on the phone?
|
Scott P. |
*negative
|
Mark M. |
no
|
Mark M. |
most threads in most OSes are paused
|
Mark M. |
that's the normal state of affairs for a thread
|
Mark M. |
they only run when there's something to do
|
Scott P. |
is there a limit to the number of threads an application can have?
|
Jun 23 | 7:55 PM |
Mark M. |
well, I wouldn't have dozens
|
Scott P. |
I'm sorry, I meant phone
|
Mark M. |
an Android app uses six or so just out of the box, all but the main application thread are usually paused
|
Mark M. |
the phone doesn't have threads
|
Mark M. |
processes have threads
|
Scott P. |
right
|
Mark M. |
the issue isn't having threads, it's *having threads doing work*
|
Scott P. |
but the processor has to handle those threads
|
Mark M. |
blocked threads are doing no work
|
Mark M. |
they consume no CPU time
|
Scott P. |
ok
|
Scott P. |
cool beans
|
Scott P. |
that's really exciting
|
Mark M. |
you might consider picking up _Concurrent Programming in Java_ if Java threading is new to you
|
Scott P. |
430 pages >.<
|
Mark M. |
yeah, well, don't read it all in one sitting... :-)
|
Scott P. |
thats the problem
|
Scott P. |
when I get a good book I can't put it down
|
Scott P. |
I went through half of your first book in 2 days
|
Mark M. |
wow
|
Scott P. |
and then I had to stop for like a week and a half to catch back up in school
|
Scott P. |
out of curiosity, how many subscriptions have you sold?
|
Scott P. |
you don't have to answer that
|
Mark M. |
lots
|
Jun 23 | 8:00 PM |
Scott P. |
lol
|
Jun 23 | 8:00 PM |
Scott P. |
nice and vague
|
Mark M. |
let's put it this way...
|
Mark M. |
I offer the Four-to-Free Guarantee, which says that book editions go Creative Commons after four years or 4,000 copies sold
|
Mark M. |
where "copies" combines print + Warescriptions
|
Mark M. |
I have plenty of editions in Creative Commons
licensed mode now (you'll see them on the Four-to-Free Guarantee tab on
each book page on the main site)
|
Scott P. |
I seee
|
Scott P. |
alright
|
Scott P. |
well
|
Scott P. |
I'll ask you 1 more oppinion question
|
Scott P. |
and then I'll leave you to it
|
Scott P. |
I accidentally ran into 2 internships, both of
which deal with mobile development with android. I've submitted my
resume, and one of them is pretty darn interested in me
|
Jun 23 | 8:05 PM |
Mark M. |
cool!
|
Scott P. |
I'm assuming that they are going to ask me for a pay range during the interview
|
Scott P. |
how much would you recommend I request?
|
Mark M. |
beats me
|
Mark M. |
that'd be driven more by what interns get nowadays, than by Android
|
Scott P. |
pfft
|
Scott P. |
yeah I suppose you are right
|
Mark M. |
it was at least when I was intern age
|
Scott P. |
how old are you now?
|
Mark M. |
too old to be answering that question
|
Scott P. |
yeah I figured
|
Mark M. |
let's just say "twice your age" is probably in the ballpark
|
Scott P. |
it just sounded by the question above that you were interning when android was around
|
Mark M. |
oh, no
|
Scott P. |
which kinda shocked me as that'd put you around my age
|
Mark M. |
when I was an intern, a portable computer weighed about 15 pounds
|
Scott P. |
anyways Mark. I'll see you later, I'm sure. I see
these office hours as too valuable of a resource not to try and take
advantage of them :-P
|
Mark M. |
hey, that's why they're here
|
Mark M. |
happy to help
|
Scott P. |
haha, well I appreciate it
|
Jun 23 | 8:20 PM |
Scott P. | has left the room |
Jun 23 | 9:00 PM |
Mark M. | turned off guest access |