Java SE Traffic Management


Think of concurrent programming as nothing more than traffic management.

You may have been lucky in your programming work so far only to have to think about a single lane of traffic, relying on the road authorities periodically to raise the speed limit to allow your vehicles to go faster. But as hardware makers lay wider freeways with multiple lanes, and as your traffic gets heavier, you may need to start worrying about how to use the capacity better to get everyone where they need to be on time.

Perhaps building a thread gate, the equivalent of a traffic signal. As this article shows, and as applied to a prime number generator, a thread gate let you manage the execution of tasks where there are dependency on the completion of some of the tasks on others in your program. Just as traffic at a four-way intersection is regulated by a rule, albeit at intersections, a simple one: each two way direction takes it in turns to avoid collisions.

Or using a BlockingQueue, already part of Java SE. A BlockingQueue is something akin to the kind of smart traffic signals that tracks waiting vehicles to decide when to allow them to pass. This blog illustrates its use in bridging the gap between two intensive tasks: parsing large amounts of data from heterogenous sources, and persisting it.

Or, looking ahead to JDK7, a variant on the BlockingQueue called the TransferQueue, described in detail here. Although not a perfect anaogy, its smarter kind of traffic signal you have have seen metering traffic entering freeways, which takes into account both waiting vehicles and the flow of traffic on the freeway.

So if you're tiring of life in the single lane, maybe its time to experiment with the Concurrency Utilities in Java SE, and look further down the freeway to those coming in the future.

Update: Do check out Brian's talk about parallelism in Java from Devoxx here (How could the Janitor forget, he was in the audience). Thanks Patrick for the tip.
Comments:

You might add Brian Goetz's talk from Devoxx 2008, available over on Parleys.com. Nice review of the problems, the currently available options, and fork/join: http://tinyurl.com/bfelrq

Patrick

Posted by Patrick Wright on March 11, 2009 at 05:49 PM PDT #

Thanks. Yes it was excellent in person too :)

Posted by Daniel Coward on March 12, 2009 at 02:30 PM PDT #

By dividing the living rooms into equal squares, it turns out that for most games, many of the squares contain unused toys that can be safely put away.http://www.watchgy.com/
http://www.watchgy.com/tag-heuer-c-24.html

Posted by rolex on December 27, 2009 at 05:09 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

A blog all about Java in all its flavors on all client platforms from smartcards to desktops and everything inbetween.

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today
Feeds