Public Member Functions | Protected Attributes | Private Attributes

T1 Class Reference

The class T1 extends Thread class. More...

Inheritance diagram for T1:
Inheritance graph
[legend]
Collaboration diagram for T1:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 T1 (JPWorld parent, float sleepIntervalSec)
 Creates a new instance of T1.
void start ()
 Starts the thread.
void stopThread ()
 Stops the thread.
void interruptibleSleep (long millis)
 Interruptible sleep (instead of Thread.sleep).
void run ()
 Prints thread's own signature and creates a pair of particles in belonging JPWorld's context every sleepItervalMillis.

Protected Attributes

JPWorld parent
 Parent where println() messages are directed to.

Private Attributes

String signature = "T1: Thread 1"
volatile boolean running = false
 Indicates if thread is (or should be) running.
volatile boolean completed = true
 Indicates that thread is completed.
int sleepItervalMillis
 Sleep interval for thread in millis.

Detailed Description

The class T1 extends Thread class.

Instance of the T2 prints out its signature until it gets stopped. It also creates a charged particle pair in associated JPWorld context.

Author:
Mikica B Kocic

Definition at line 10 of file T1.java.


Constructor & Destructor Documentation

T1.T1 ( JPWorld  parent,
float  sleepIntervalSec 
)

Creates a new instance of T1.

Parameters:
parentowner of the thread
sleepIntervalSecsleep interval in seconds

Definition at line 40 of file T1.java.

References parent, and sleepItervalMillis.

Referenced by T3.run().

    {
        this.parent = parent;
        this.sleepItervalMillis = (int)( sleepIntervalSec * 1000f );
    }

Member Function Documentation

void T1.interruptibleSleep ( long  millis )

Interruptible sleep (instead of Thread.sleep).

Parameters:
millis- the length of time to sleep in milliseconds.

Definition at line 75 of file T1.java.

Referenced by T3.run(), and run().

    {
        try {
            Thread.sleep( millis );
        }
        catch( InterruptedException ie ) {
            /* ignored */
        }
    }
void T1.run (  )

Prints thread's own signature and creates a pair of particles in belonging JPWorld's context every sleepItervalMillis.

Reimplemented in T3.

Definition at line 90 of file T1.java.

References completed, JPWorld.createPairOfChargedParticles(), interruptibleSleep(), parent, JPWorld.println(), running, signature, and sleepItervalMillis.

    {
        while( running )
        {
            parent.println( signature );
            
            parent.createPairOfChargedParticles( 1, 10.0 + Math.random () * 5.0 );

            interruptibleSleep( sleepItervalMillis );
        }
        
        completed = true;
    }
void T1.start (  )

Starts the thread.

Definition at line 50 of file T1.java.

References completed, and running.

Referenced by T3.run(), and JPWorld.startTests().

    {
        if ( ! completed ) {
            return;  // Allow only single thread per instance
        }

        running = true;
        completed = false;
        super.start ();
    }
void T1.stopThread (  )

Stops the thread.

Definition at line 64 of file T1.java.

References running.

Referenced by T3.run().

    {
        running = false;
        this.interrupt (); // interrupt ongoing sleep
    }

Member Data Documentation

volatile boolean T1.completed = true [private]

Indicates that thread is completed.

Definition at line 22 of file T1.java.

Referenced by run(), and start().

JPWorld T1.parent [protected]

Parent where println() messages are directed to.

Definition at line 32 of file T1.java.

Referenced by T3.run(), run(), and T1().

volatile boolean T1.running = false [private]

Indicates if thread is (or should be) running.

Definition at line 17 of file T1.java.

Referenced by run(), start(), and stopThread().

String T1.signature = "T1: Thread 1" [private]

Reimplemented in T3.

Definition at line 12 of file T1.java.

Referenced by run().

int T1.sleepItervalMillis [private]

Sleep interval for thread in millis.

Definition at line 27 of file T1.java.

Referenced by run(), and T1().


The documentation for this class was generated from the following file: