§5.2 Explicit team activation

(a) Activation block

A team can be activated thread local by the block construct

within (myTeam) { stmts }

If stmts has only one statement this can be abbreviated to

within (myTeam) stmt

In these statements, myTeam must denote a team instance. For the time of executing this block, this team instance is activated for the current thread, which has entered the within block.

The within block statement guarantees that it leaves the team in exactly the same activation state as it was in when entering this block. This includes the cases of exceptions, meaning that deactivation will also occur if the execution of the block terminates abnormally.

(b) Imperative activation

Each team class implicitly provides methods from the predefined interface org.objectteams.ITeam (super interface of all team classes) to control team activation disregarding the block structure of the program. The methods activate() and deactivate() are used to activate and deactivate a team instance for the current thread.
If a team should be de-/activated for another thread this can be done by the methods activate(Thread aThread) and deactivate(Thread aThread). In order to achieve global activation for all threads the predefined constant org.objectteams.Team.ALL_THREADS is passed to these methods (e.g. activate(Team.ALL_THREADS)).
Note, that this methods make no guarantees with respect to exceptions.

(c) Multiple and mixed activations

  • If activate() is invoked on a team instance that has been explicitly activated before, this statement has no effect at all (note the difference in §5.3.(a) below).
    The same applies to deactivating an inactive team.
  • If a team was already active when entering a within block, it will remain active after leaving the block.
  • If the team was active on entry of a within block and if deactivate() is invoked on the same team instance from within the within block, leaving the block will re-activate the team.