CS202 Site Index
- Main
- Information
- Registration
- Announcements
- Lectures
- Assignments
- Submit
- View
- Reference
- Passwords
Java logo CS202 - Spring 1999
Transition to Java

Lectures: Week 3

divider line
Mon, 8 Feb  
  • JFC:
    - Panels, Layout managers, Icons, JButton, JLabel
  • Threads:
    - multi-task computation, sometimes simulated
    - allows use of more than one processor
    - allows interleaving computation with blocked input/output
    - writing code that blocks and waits is simpler, usually more efficient, than spinning in a loop
    - Thread class or Runnable interface
    - usually just override/implement run() method, and perhaps object constructor
    - threads can be preempted (stopped) at any time to allow other threads to execute
    - example: printing thread
  • Thread synchorization
    - sometimes threads need to interact, access common resources
    - often need to ensure mutual exclusion, or use it to ensure some other property
    - can declare method to be synchronized
    - only one thread can be inside synchronized code
    - example: producer, consumer problem
  • Reading:
    - refer to Sun tutorials on threads
    - read about synchronization in the Java Language Specification.
    - On To Java: Ch 47
  • Assignment #1 returned

 
Wed, 10 Feb  
  • Networking:
    - Discussion about A3, client, server
    - IP, TCP, streams, protocols
    - Socket, ServerSocket classes
    - accepting connections, need for server threads
    - initiating connections
  • Reading:
    - JavaSoft tutorial on networking
    - Example: ClientListen.java. Try sending the requestRoot file to www.cnn.com on port 80.
    - Example: ServerListen.java. Try starting this up on port 80 then go to localhost with Netscape.

 
Fri, 12 Feb  
  • Threads:
    - implements Runnable, or extends Thread
    - override run(), perhaps also constructor
    - example: SimpleThread.java
    - usually implement Runnable to get concurrent execution
    - extend Thread when want to add Thread-local variables, model more complex interaction
    - pre-emption: ability to stop a thread and pass control to another
    - time-slicing: pre-emption done at some regular interval
    - blocking: waiting until some event (usually i/o) occurs
    - Thread.currentThread() returns current thread object
    - killing threads: difficult to ensure consistent state among objects, locks...
    - ThreadGroups - create cooperative threads that die when signalled via some internal variable
    - yield: interrupt execution until other threads have had a chance
    - sleep: interrupt execution and request to resume execution after given interval
    - selfish threads: run without relinquishing control, if no preemption, will run forever
  • Monitors
    - monitors protect sections of code, allowing mutually exclusive access (only one thread at a time)
    - threads wait in a queue to enter monitor
    - reentrant
    - deadlock: thread T1 in monitor M1 waiting for M2, and T2 in M2 waiting for M1, dining philosophers
    - wait: release monitor, continue later
    - notifyAll: wake up waiting threads, which will try reacquire monitor and continue execution
    - example: producer/consumer problem
  • Assignment #2 returned

divider line
Copyright 1999, Rimon Barr, Cornell University RBcs202-sp99: l.3.html (17602)