HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Turbo-Charging Java for Real-Time Applications"
Vol. 9, Issue 7, p. 32

	



Listing 1

PoolContext.enter(); // Allows for „stack‰ allocations.
try {
    ...
    ConcurrentContext.enter();
    try {
        // Concurrent executions have access to
        // the „stack‰ objects of the outer pool context.
        ConcurrentContext.execute(logic, ...);
        ConcurrentContext.execute(logic, ...);
    } finally {
        // Waits for concurrent executions to complete.
        ConcurrentContext.exit();
    }
    ...
} finally {
    // Recycles all stack objects including
    // objects allocated by concurrent threads.
    PoolContext.exit();
}

Listing 2

Matrix[] inputs = ...;
Matrix[] results = new Matrix[inputs.length];
for (int i=0; i < inputs.length; i++) {
    PoolContext.enter() {
    try {
        Matrix tmp = inputs[i].inverse();
        ... // Some function of inputs/results
        results[i] = (Matrix) tmp.export();
    } finally {
        // Recycles all temporary objects allocated.
        PoolContext.exit();
    }
}

Listing 3

// Defines UDP message internal fields.
class Message extends Struct { ... }

class MulticastConnection extends Thread {
    MulticastSocket socket;
    public void run() {
        byte[] bytes = new byte[1024];
        DatagramPacket packet
            = new DatagramPacket(bytes, bytes.length);
        Message msg = new Message(bytes);
        while (!socket.isClosed()) {
            PoolContext.enter();
            try {
                socket.receive(packet);
                ... // Process msg (real-time).
                packet.setLength(bytes.length);
            } catch (IOException ioError) {
                ... // Process error.
            } finally {
                PoolContext.exit();
            }
        }
    }
}

 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.