Monthly Archives: October 2015

Even though we all want everything goes parallel and each task is independent with others totally, sometimes it is not simply as we think. Everything has an order, what we can do is to let independent things work at the same time, and let dependent things work by order.

A future gives us a simple way to deal with it. Each future is like an independent tasks and it starts running concurrently. But within a future, each steps in a task run by order.

Here we give two examples. one is only one task, the other is multiple tasks.

Note: Await.result will block the thread with a mandatory timeout duration. Blocking is not a good thing– you should block only if you really have to — but this is useful, in particular for testing purposes. blocking in general is discouraged when working with Futures and concurrency in order to avoid potential deadlocks and improve performance. Instead, use callbacks or combinators to remain in the future domain:

Recently, I need to do some social media collectors to scrawling data from multiple sources, like twitter, google news, rss, etc. Twitter already has nice java library to get data, named twitter4j. But for other sources, we need to parse the data by myself. Most of them can return xml format back, like google news and rss. So the rest thing is to know how to parse xml, that’s enough. (Note: even though most files use xml, but its detail structure is different sometimes. For example, some use “channel” -> “item” structure, but others are using “entry” structure.)