ActiveJava

Copyright Tristan Aubrey-Jones May 2008.

Abstract: A project investigating and developing an implicitly concurrent programming language, based on a metaphor taken from the physical world is reported. Uses a programming paradigm where programs consist of systems of autonomous agents, or active objects which communicate via message passing. A language enhancing Java with actors and linear types is presented. Example programs are written, compiled, and executed to evaluate the usefulness of the language. The language found to provide a familiar notation for implicit parallelism, and a compelling new model for concurrency, combining the performance of shared variables with the elegance of message passing.

Introductory Slides (PDF), Report (PDF),
ActiveJava compiler prototype (ajavac), ActiveJava runtime library (ajava_lang).

Examples:

calc - pocket calculator actor program
dining - dining philosophers actor program (never deadlocks)
sort - parallel quicksort implementation ("SortBenchmark" sorts 10,000 random integers using actors, java threads, and sequentially and compares)
To compile examples use:
compile.bat ./calc
compile.bat ./sort
compile.bat ./dining
To run examples use:
run ./calc Main
run ./dining Main
run ./dining Main fast
run ./sort Main
run ./sort SortingBenchmark

IntSorterThread.java

home Home   up Up   ( Download )


import org.taj.ajava.util.*; public class IntSorterThread { /** * Sorts an array using recursive quicksort. */ private static class WorkerThread extends Thread { private IntegerArray array; public WorkerThread(IntegerArray array) { this.array = array; } public IntegerArray removeArray() { IntegerArray a = array; array = null; return a; } public void run() { if (array.size() <= SorterMethods.MIN_PARTITION_SIZE) { SorterMethods.sortArray(array); } else { int pivotIndex = SorterMethods.choosePivotIndex(array); int pivotNewIndex = SorterMethods.partitionArray(array, pivotIndex); int[] indices = new int[1]; indices[0] = pivotNewIndex; IntegerArray[] parts = array.split(indices); WorkerThread lhs = new WorkerThread(parts[0]); WorkerThread rhs = new WorkerThread(parts[1]); lhs.start(); rhs.start(); // sort concurrently... try { lhs.join(); rhs.join(); } catch (InterruptedException ex) { throw (new RuntimeException(ex)); } parts[0] = lhs.removeArray(); parts[1] = rhs.removeArray(); array.merge(parts); } } } /** * Inplace quicksort. * @param array * @return */ public IntegerArray sort(IntegerArray array) { WorkerThread t = new WorkerThread(array); t.start(); try { t.join(); } catch (InterruptedException ex) { throw (new RuntimeException(ex)); } return t.removeArray(); } }