Ben Williamson wrote:
> I think a better way to have phrased my question is....
> 
> "public final void suspend()
> This method is deprecated. May cause deadlocks."
> 
> is in the javadoc for the Thread class....

Yes. It's been deprecated for over a decade, including "traditional"
Java since at least Java 1.4, and perhaps earlier.

> is there an alternative to
> this method so I do not have to kill and completly start over each time
> I need to pause my activity.

I don't know anything about your application. As such, it is very
difficult to provide specific advice, since there are many patterns for
Java concurrency.

IMHO, threads should be totally disposable. You should be able to signal
your threads to shut down, and they should shut down of their own accord
quickly. Whether you use an a LinkedBlockingQueue or a Semaphore or
whatever for the signaling is more a question of how you are organizing
the work in the background threads.

The key is for the threads to be disposable, but for those threads to be
able to pick up where the others left off when the activity is resumed.
Then "start[ing] over each time" doesn't happen, as far as work is
concerned.

This means that threads should not hold state. My personal preference is
the job queue pattern: threads pull jobs off a LinkedBlockingQueue,
block on the queue if the queue is empty, and exit the queue-blocking
loop if they get a "kill job" off the queue. The jobs hold state for
what needs to be done.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 2.0 Published!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" 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-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to