\

Home Corporate Contacts

TETware Java API Overview


Products
Solutions

Information

Datasheet
Documentation
FAQ
Knowledgebase

16. Using threads


Thread Creation

When a test purpose creates a new thread it should use the TetThread class. This can be done either by subclassing TetThread or by creating a TetThread object using an object of a class which implements java.lang.Runnable. The result of using some other means to create a new thread in a Java test case is undefined. The test case should use one of the following constructors:


      public TetThread(TestSession ts, Runnable target, String name,
                 long waitTime)
      public TetThread(TestSession ts, Runnable target, long waitTime)
      public TetThread(TestSession ts, String name, long waitTime)

The target and name arguments are simply passed to the constructor of the superclass java.lang.Thread. The ts argument is used to determine to which thread group the new thread will belong. A new thread group is created for each test purpose, startup and cleanup method. The waitTime argument specifies the number of seconds for which the TCM thread cleanup code will wait for the thread to finish after the main thread returns control to the TCM. The purpose of this wait time is to allow other threads some grace in the event of an abnormal return from the main thread. Normally, the test purpose itself should wait for all non-main threads to terminate by calling Thread.join().


Dealing With Left-over Threads

Each time the main thread returns to the TCM, any other threads which were created using one of the supported constructors are cleaned up. This is done after the following methods return:

  • The startup() and cleanup() methods.
  • Each test purpose method.
  • tet_main().

The API interrupts a thread which does not exit within the grace time specified in the constructor by calling Thread.interrupt(). If the thread still does not terminate, the TCM aborts the test case. Note that the use of Thread.stop() is not a recommended way of terminating threads and is deprecated in Java 2.


Synchronisation Requests in Multiple Threads

See notes on "Synchronisation requests in multi-threaded test cases" in the chapter entitled "The Thread-safe C and C++ APIs" in the TETware Programmers Guide.

Return to Contents



Home Contacts Legal Copyright Corporate News

Copyright © The Open Group 1995-2012, All Rights Reserved