180 likes | 323 Views
Curve Bank Project. Baravelle Spiral Robert Lai CS491. Recall. Fractal Curves within curves Patterns within patterns Iterations within iterations Not actually a curved design, the spiral effect comes from the way the structure is drawn How to draw the Baravelle Spiral. Recall (count.).
E N D
Curve Bank Project Baravelle Spiral Robert Lai CS491
Recall Fractal Curves within curves Patterns within patterns Iterations within iterations Not actually a curved design, the spiral effect comes from the way the structure is drawn How to draw the Baravelle Spiral
Recall (count.) • FINITE AREA • INIFINTE PERIMETER or FRACTAL e.g. Koch Snowflake, Mandelbrot Set • Geometric Series • Converges, area • Harmonic Series • Diverges, fractal
Baravelle Spiral • Two different format • Application • Allow user to download and run on their own computer • jar format • jar cvfm <jar file name> mymanifest <dir> • Applet • Allow user to see and run it on the web browser
Multithreading One action at a time? Programming step by step Difficult to do. e.g. human body We need multithreading
Multithreading (2) • Describes a program that is designed to have parts of its code execute concurrently • Concurrent Programming • OS: • Preemptive multithreading • Cooperative multithreading
Preemptive multithreading • The operating system to determine when a context switch should occur • The system may make a context switch at an inappropriate time • Causing priority inversion • Priority inversion: scenario where a low priority task holds a shared resource that is required by a high priority task
Cooperative multithreading • Relies on the threads themselves to relinquish control once they are at a stopping point • Create problems if a thread is waiting for a resource to become available
Baravelle Spiral • Application • SwingWorker • Applet • Thread
SwingWorker • 3rd Version • An object creates a thread to execute a time-consuming operation • Is not in the Swing release • http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html
private static class ThreadVar{…} • Class to maintain reference to current worker thread under separate synchronization control. • protected synchronized Object getValue(){…} • Get the value produced by the worker thread, or null if it hasn't been constructed yet. • private synchronized void setValue(Object x){…} • Set the value produced by worker thread • public abstract Object construct();
public void interrupt(){…} • public Object get(){…} • Return the value created by the construct method. • Returns null if either the constructing thread or the current thread was interrupted before a value was produced. • public SwingWorker(){…} • Start a thread that will call the construct method and then exit. • public void start(){…} • Start the worker thread.
Thread • A thread is a thread of execution in a program • Allows the JVM to run an application to have multiple threads of execution running concurrently • private Thread timerThread; • public void actionPerformed( ActionEvent actionEvent ) { …check the event taken … startThread(); … } • private void stopThread() { if(timerThread.currentThread() != null) timerThread.currentThread().interrupt(); timerThread = null; }
private void startThread() { stopThread(); Runnable r = new Runnable() { public void run() { runWork(); } }; timerThread = new Thread(r); timerThread.start(); } • private void runWork() { … my working procedure … }
Runnable • Interface • is designed to provide a common protocol for objects that wish to execute code • implemented by class Thread
Conclusion • More understanding of graph programming • Give me another way to understand math concept