Virtual Machinery logo Task Manager - Demos
Home Task Manager Simple example Manual Demo Other Products

Task Manager - a simple example

The first step is to create a TaskManager instance -

TaskManager myTaskManager = new TaskManager();

Then we need to create a task to add to the task manager. Here's a simple task that prints a message to the console, waits for five seconds then writes another message to the console.

First we create a Task -

Task myTask = new Task();

Then we set the variables that determine the behaviour of our class -

myTask.setSequenceNumber(1);
myTask.setName("My Task");

Now we need to create the code for our task -

Runnable code = new Thread() {
  public void run() {
    System.out.println("Running code for My Task");
    try { Thread.sleep(5000);}
    catch (InterruptedException ie) {}
    System.out.println("Completed code for My Task");
  }
};
myTask.setCode(code);

We add the task to the Task Manager -

myTaskManager.addTask(myTask);

And now we can run the task manager -
myTaskManager.startTasks(true);

And you can see the following in the console -

Running code for My Task
Completed code for My Task

You can find out more about using the Task Manager classes here . There is also demonstration code and applications which you can find out about here .