Curve Bank Project Baravelle Spiral Robert Lai CS491.

18
Curve Bank Project Baravelle Spiral Robert Lai CS491
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    218
  • download

    1

Transcript of Curve Bank Project Baravelle Spiral Robert Lai CS491.

Page 1: Curve Bank Project Baravelle Spiral Robert Lai CS491.

Curve Bank ProjectBaravelle Spiral

Robert LaiCS491

Page 2: 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

Page 3: Curve Bank Project Baravelle Spiral Robert Lai CS491.

Recall (count.)• FINITE AREA

• INIFINTE PERIMETER or FRACTALe.g. Koch Snowflake, Mandelbrot Set

• Geometric Series• Converges, area

• Harmonic Series• Diverges, fractal

Page 4: Curve Bank Project Baravelle Spiral Robert Lai CS491.
Page 5: Curve Bank Project Baravelle Spiral Robert Lai CS491.

Baravelle Spiral• Two different format

• Application• Allow user to download and run on their own co

mputer• jar format• jar cvfm <jar file name> mymanifest <dir>

• Applet• Allow user to see and run it on the web browser

Page 6: Curve Bank Project Baravelle Spiral Robert Lai CS491.

Multithreading

• One action at a time?• Programming step by step

• Difficult to do.• e.g. human body

• We need multithreading

Page 7: Curve Bank Project Baravelle Spiral Robert Lai CS491.

Multithreading (2)• Describes a program that is designed to

have parts of its code execute concurrently

• Concurrent Programming

• OS:

• Preemptive multithreading

• Cooperative multithreading

Page 8: Curve Bank Project Baravelle Spiral Robert Lai CS491.

Preemptive multithreading • The operating system to determine whe

n 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 tas

k holds a shared resource that is required by a high priority task

Page 9: Curve Bank Project Baravelle Spiral Robert Lai CS491.

Cooperative multithreading • Relies on the threads themselves to reli

nquish control once they are at a stopping point

• Create problems if a thread is waiting for a resource to become available

Page 10: Curve Bank Project Baravelle Spiral Robert Lai CS491.

Baravelle Spiral• Application

• SwingWorker

• Applet• Thread

Page 11: Curve Bank Project Baravelle Spiral Robert Lai CS491.

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/uis

wing/misc/threads.html

Page 12: Curve Bank Project Baravelle Spiral Robert Lai CS491.

• private static class ThreadVar{…}• Class to maintain reference to current worker thre

ad under separate synchronization control.

• protected synchronized Object getValue(){…}• Get the value produced by the worker thread, or n

ull if it hasn't been constructed yet.

• private synchronized void setValue(Object x){…}• Set the value produced by worker thread

• public abstract Object construct();

Page 13: Curve Bank Project Baravelle Spiral Robert Lai CS491.

• 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 an

d then exit.

• public void start(){…}• Start the worker thread.

Page 14: Curve Bank Project Baravelle Spiral Robert Lai CS491.

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;

}

Page 15: Curve Bank Project Baravelle Spiral Robert Lai CS491.

• private void startThread() {

stopThread();

Runnable r = new Runnable() {

public void run() { runWork(); }

};

timerThread = new Thread(r);

timerThread.start();

}• private void runWork() { … my working procedure … }

Page 16: Curve Bank Project Baravelle Spiral Robert Lai CS491.

• Runnable• Interface• is designed to provide a common protocol for obje

cts that wish to execute code• implemented by class Thread

Page 17: Curve Bank Project Baravelle Spiral Robert Lai CS491.

Conclusion• More understanding of graph

programming

• Give me another way to understand math concept

Page 18: Curve Bank Project Baravelle Spiral Robert Lai CS491.

DEMO