20-CS-694 | Advanced Programming Techniques | Spring 2012 |
---|---|---|
Synopsis |
Threads | |||||
Synchronize |
|
Thread synchronization - hit 'Reset' then 'Start' Four rectangles are tied to threads and advance horizontally as threads are run. A paint method repaints the applet whenever a rectangle moves. But four threads have access to the same paint method. If the method allows more than one thread to run it at a time, weird things happen: the result is a flicker. |
|||
Monitor |
|
Application of a Monitor - hit 'Reset' then 'Start',
move sliders to adjust thread priorities A monitor is used to control the running of threads. Threads attached to Process objects invoke the put method of the monitor initially and when they are 'suspended'. They wait in the put method until the Kicker thread invokes a notify in the next method of the monitor, releasing one of them. |
|||
Data-Driven Computation |
|
Producer/Consumer - hit any button One of the most important applications of threads is the implementation of networks of processes that produce and consume tokens of various kinds. Such networks support data-driven computation (computation on demand only). |
|||
Networking | |||||
Datagram |
|
Simple Client-Server, UDP - hit 'Start Server' then 'Get Next Date' Create and send a UDP packet from a client to a server. The server determines the current time and day and responds to the client's packet by sending a packet with the date. The client pulls the date from the packet and displays it. |
|||
Echo Server |
|
Simple Client-Server, TCP - hit 'Start Server' then
'Connect' twice, then enter text into an 'Input' field and hit 'Send It'. Create a TCP connection between client and server and send packets in both directions. Text sent by a client is echoed back to the client. |
|||
Bot |
|
Teleportation - hit 'Start Server' then
'Connect' then hit 'Send It' An application is started on the client side. The application just prints a sequence of numbers (3, 5, 6, 9, 10, 12, 15, 15, 20, 21, and so on) to an available JTextArea. Printing begins on the client. But after the 18 is printed, the application suspends itself, is teleported to the server whereupon the server resumes the application which then prints on the server's JTextArea. This example requires application class information on client and server but with reflection (below) that is unnecessary. |
|||
RMI |
|
Remote Method Invocation - hit 'Get Date' A method is invoked on a remote machine, but it appears to be invoked on the local machine. |
|||
Internet | |||||
Webserver |
|
Hit 'Start Server', start a browser, point to localhost:8080. |
|||
Reflection | |||||
Send Applets |
|
Choose 'Weather' or 'Sudoku' on the Transmitter applet, then hit 'Send
it' Hit 'Start the Applet' on the Receiver applet. There is no class information needed on the Receiver - the bytes sent are used to construct the classes that are run. |
|||
Get Libs |
|
Hit 'Choose' and select an mp3 file from the Chooser. Hit 'Play' to play it. An MP3 player library is received from gauss and its methods are invoked. |
|||
Graphics | |||||
Checkers |
|
Images controlled by mouse movement Hit 'Start' on both boards. Hit 'Update' on both boards. Hit 'Invite' on one board. Hit 'Accept' on the other board. Red player can drag a checker to another square. When Red player is done, Black player gets a chance. |
|||
Animation |
|
Simple animation Drag a dot with the mouse |
|||
Animation |
|
Red-Black Tree demo |
|||