Click or drag to resize

Programmer's Guide

Here is a very simple example application. It adds two numbers together and writes the result to the console.

package stkscalabilitysdk;

import agi.parallel.client.ClusterJobScheduler;
import agi.parallel.client.IJobScheduler;
import agi.parallel.client.Job;
import agi.parallel.infrastructure.Task;

public class SimpleExample {
    public static void main(String[] args) {
        try (IJobScheduler scheduler = new ClusterJobScheduler("localhost")) {
            Job job = scheduler.createJob();
            Task task = new SimpleTask(1, 1);
            System.out.println("Result = " + task.getResult());

    public static class SimpleTask extends Task {
        private int a;
        private int b;

        public SimpleTask(int first, int second) {
            this.a = first;
            this.b = second;

        public void execute() {
            this.setResult(this.a + this.b);

Lets compile and run this example. To do this open a cmd prompt and enter the following commands. First, create three folders (stkscalabilitysdk, lib, and classes) that will be used for all the example applications in this programmer's guide.

mkdir stkscalabilitysdk
mkdir lib
mkdir classes

Copy agi.parallel.client-1.7.0.jar to the lib directory. For instance:

copy [PathToSTKScalabilityApiJavaFolder]\Jars\agi.parallel.client-1.7.0.jar lib

Save (copy and paste the above code) to the stkscalabilitysdk folder and compile.

javac -cp lib\agi.parallel.client-1.7.0.jar -d classes stkscalabilitysdk\

Before running the application, make sure to jar the class files.

jar cvf SimpleExample.jar -C classes/ .

Finally, run the application!

java -cp "lib\agi.parallel.client-1.7.0.jar;SimpleExample.jar" stkscalabilitysdk.SimpleExample
Important note Important

Make sure to run the jar command before running the application. If the class files are run directly, the ClassNotFoundException exception will be thrown and the task will not run correctly. Below is an example of the output received when the jar step is missing:

C:\DoNotDoThis>java -classpath "lib\agi.parallel.client-1.7.0.jar;classes" stkscalabilitysdk.SimpleExample
WARNING: Detected that task class (stkscalabilitysdk.SimpleExample$SimpleTask) is not run from a jar. The task class may fail to load. Please see documentation for details.
Result = agi.parallel.infrastructure.serialization.MessageSerializationException: Could not deserialize object graph

The application first connects and submits a task to the coordinator. An agent will be assigned the work and execute the task in an isolated process. The result of the task is finally sent back to the client. That is the basic structure of an application.

Step through the code in an IDE line by line, examine the messages written from the coordinator and agent consoles. Take note of how the coordinator and agent respond stepping through each line. For example, stepping past job.submit will cause the coordinator console to log "added task to queue". What this means will be discussed later.

Step Through Code

Continue to experiment with this application. Try to add more tasks to the job, set the jobs's TaskEnvironment, or modify some of the job options. As this example shows, the basic structure and core pieces of an application written with the API are simple but powerful!

Next Steps

With a rudimentary example application finished, explore the help system and move on to more advanced topics. The following sections give various topics in the API more treatment.


Read this if you want to...


Read a step by step narrative of another sample application.

How To

Get solutions to common patterns in the API.

Key concepts

Understand the key concepts and building blocks of the product.


Get instructions on how to step through the remote task code.

Frequently Asked Questions

Get answers to frequently asked questions.


Gain a firm understanding of the internals of the product.

Library Reference

Explore what is available in the API.

STK Scalability 1.7 API for Java