20-CS-694 Advanced Programming Techniques Spring 2012
Threads

Interfaces, Exceptions, Graphics, Animation, Threads, Reflection, Networking, RMI, JDBC, JNI

    All lectures

Timers, Multiple Threads, Critical sections, Streams

    1.   TimerTest.java

  -   Implementation of a Timer class that stops an application after a given amount of time. The application implements the interface Off which requires the method void off(String). The application creates a new object of the Timer class, passing a reference to itself and the number of seconds it wants the timer to sleep. The application need not be threaded but in this example it is. The application implements the off method to receive a time from the Timer object when it wakes up and to turn itself off. The String argument to off is written into this example so the applet can show how much time the timer took before it went off by passing that time as a String to the Application. Normally, off will have no arguments.
 
    2.   SecTimer.java

  -   Count seconds - try hitting 'Start' several times - references to running Threads are maintained with Java even if the user's application loses them.
 
    3.   SecTimer.java

  -   Same as the previous applet except the Runnable interface is used.
 
    4.   RRProcess.java

  -   Round robin multitasking is supported by using threads.
 
    5.   Race.java
Race1.java
Race2.java

  -   The overridden update method is a critical sections - only one thread can access it at a time. One applet shows what happens if this is not done, the other shows a synchronized update. Hit 'Reset' then 'Start'.
 
    6.   RRSched.java

  -   Round robin scheduling with control over the time resource each thread is given. This applet uses a Monitor to control the threads.
 
    7.   CheckBoxApplet.java

  -   This shows how demand-driven processes can easily be inserted into existing code. In this case a monitor is used to suspend a loop for user input.
 
    8.   InputStreamTest.java

  -   This is another producer-consumer example. Type characters into the input window and see the result in the output window.
 
    9.   JoinIt.java

  -   This example shows how to join threads.
 
    10.   StreamTest.java
ConnectEntry.java
ConnectionRefusedException.java
Consumer.java
PC.java
Producer.java
Stream.java

  -   Connect many consumers to the same producer without losing any tokens. See comments in the 1st java file (StreamTest.java) for details.