Archive for October, 2010
Android (Java) Concurrency
by CodeStream on Oct.11, 2010, under Android Development
Interested in expanding your knowledge of multithreading? Do you already know a little bit about Runnables and Threads… They’re not very streamlined all on their own are they?
Java introduced a package in 1.5 (I think) which went unknown to me for a while. Wish I’d found it sooner because I was doing things the hard way, or rather, the more meticulous way. So what is this package called? :
java.util.concurrent <- Here’s an api link for those who’d like to learn about it that way.. be warned it’s a pretty large bit of info to take in all at once
What does this package offer?
- Automatically manage a pool of threads
- Use a fixed thread count or..
- Create as many threads as needed, reusing threads when possible
- Start up single tasks normally, while manage them under your thread pool
- Blocking until a pool of threads are all finished
- Optional timeout period
- Repeating tasks at a rate asynchronous to their execution time!
- Yes, this means it’s perfect for timers.
- Or wait until a specific elapsed time AFTER execution
- Return values, or Throw exceptions from Threads
- Shut down thread pools and single tasks with many options
- Shut down in an orderly fashion by rejecting new tasks but allowing existing tasks to complete
- Quickly shut down by interrupting tasks in progress
- Optionally block while waiting for a shut down
- Optional timeout period if chosen to block during shut down
- See if a task was cancelled or if it finished
- +Plus tons of even cooler stuff
