Google

HelloNewTeam

Creating Teams with java code

In the previous section we ran a simple HelloWorld program in the kernel team, so now it's time to start creating our own teams and playing with them. For this example we'll be using the HelloNewTeam.java program, so compile and run it.
  tservo@satolove tutorial> jikes -classpath <install dir>/share/kaffe/JanosVM.jar HelloNewTeam.java
  tservo@satolove tutorial> janosvm -config tutorial.config HelloNewTeam
  kernel says hello
  Child says hello
From the source code we can see that the first thing to print something is:
  System.out.println(Team.current().getName() + " says hello");
Since the class is being run in the kernel the call to Team.current() will return the handle associated with the kernel, hence we get its name. Next we create a child with the default resource requirements and the name "Child".
  TeamHandle child = Team.create("Child");
However, besides the GC threads there is nothing else executing within the context of this team, so we need to visit the team in order to get something done. The child.switchTo() call will switch the current thread to the context of the child team and execute the same code to print out the name of the current team. Finally, we call child.terminate() to terminate the child team and return its resources to the VM.

Creating teams with JSI

In addition to the Java interface we can also use JSI to create and terminate teams.
  tservo@satolove tutorial> janosvm -config tutorial.config -name janosvm \
    -jsitcpport 14000 -noexit &
  tservo@satolove tutorial> jsihey janosvm create team with name "Parent" \
    then print "%(result:d)\n"
  2
The jsihey command tells the VM to create a team with the name "Parent" and then it prints out the unique identifier associated with the team. This id is then used for all interactions with the team when using JSI. To get a listing of all the teams and their id's just execute the following:
  tservo@satolove tutorial> jsihey janosvm list teams
  Normal Reply:
    id = `1'
    name = `kernel'
    id = `2'
    name = `Parent'
Now that we have our new team let's run HelloNewTeam and see if its output has changed:
  tservo@satolove tutorial> jsihey janosvm execute run of team 2 with class \
    HelloNewTeam then nothing
  Parent says hello
  Child says hello
Well it seems to work, now let's terminate the parent:
  tservo@satolove tutorial> jsihey janosvm delete team 2 then nothing
That should be enough for now, shutdown the VM and let's move on to the next section.
Copyright (c) 2000, 2001 The University of Utah and the Flux Group.
All rights reserved.

Permission to use, copy, modify, distribute, and sell this documentation for any purpose is hereby granted without fee, provided that the above copyright notice(s) appear in all copies.