Slide design: Dr. Mark L. Hornick

Slides:



Advertisements
Similar presentations
SE2811 Week 8 Monday (last drop day) The Command Pattern Lambda Expressions SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr.
Advertisements

Week 5, Day 3: Observer Today Reducing coupling with the Observer The Observer pattern in Java APIs Posting events to a UI worker thread SE-2811 Slide.
Week 3, Day 1: Processes & Threads Return Quiz Processes Threads Lab: Quiz Lab 3: Strategy & Factory Patterns! SE-2811 Slide design: Dr. Mark L. Hornick.
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!  And before that?  Review!  And before that?  if and switch statements.
Week 3, Day 1: Processes & Threads Processes Threads SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
Internet Software Development Controlling Threads Paul J Krause.
Synchronized and Monitors. synchronized is a Java keyword to denote a block of code which must be executed atomically (uninterrupted). It can be applied.
CS2910 Week 1, Class 2 Today Announce Prof. Michael Vieau’s S-341 6p Thurs Wk 2 Assignment for tomorrow Data Encoding, Part 1 Parsing Data Muddiest Point.
Today C/C++:.h/.cpp; compiling and linking Fourier Transform (corrected) Nyquist Theorem Audio sampling rates SE-2811 Slide design: Dr. Mark L. Hornick.
Week 3, Day 2: Threads Questions about Threads “Multithreading” in Swing Lab tomorrow: Quiz Lab 3: Threading! SE-2811 Slide design: Dr. Mark L. Hornick.
The Singleton Pattern SE-2811 Dr. Mark L. Hornick 1.
CS2852 Week 3, Class 2 Today Stacks Queues SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
CS2910 Week 5, Class 2 Today DNS Muddy Points More HTTP Headers Review for Midterm Exam This coming Monday: Midterm Exam SE-2811 Slide design: Dr. Mark.
SE1011 Week 8, Class 3 Today Designing Code SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 1.
SE1011 Week 6, Class 1 Today Return Half Exam 2 (cont.) Object Oriented Programming (cont.) Muddiest Point Next Half Exam: Week 7, Monday SE-1011 Slide.
CS2852 Week 6, Class 1 Today The run-time stack Writing and proving recursive methods SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors:
CS2852 Week 5, Class 2 Today Queue Applications Circular Queue Implementation Testing SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors:
CS2852 Week 7, Class 1 Today Binary Search Tree Implementing add Implementing find Return Quiz 4 (second attempt) Both sections are graded SE-2811 Slide.
Week 3, Day 3: Singleton Pattern Quiz Status Russia Opportunity Muddiest Points – Patterns SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick.
Week 7, Day 3 Half-Exam 2 A New Pattern SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
CS2852 Week 6, Class 2 Today Class exercise: Implementing a recursive method Binary Search Trees Tomorrow: Quiz at start of lab Implementing a recursive.
Week 5, Day 3: Decorator Decorators Muddiest Point Tomorrow: Quiz on lab reading: web.msoe.edu/hasker/se2811/labs/5/ SE-2811 Slide design:
Week 5, Day 2: Decorator Decorators Muddiest Point Tomorrow: Quiz on lab reading: web.msoe.edu/hasker/se2811/labs/5/ SE-2811 Slide design:
Today Quiz not yet graded Final report requirements posted More on Multithreading Happens-Before in Java SE-2811 Slide design: Dr. Mark L. Hornick Content:
CS2852 Week 3, Class 2 Today Big-O runtime analysis Linked Lists Muddiest Point Lab Quiz Includes writing a method from ArrayList class (See next slide)
Week 7, Class 1: The Command Pattern (cont.) Get Ready for Poll Everywhere Labs 2 & 3 returned Lab 7 due this evening at 11pm Quiz tomorrow at start of.
Week 10, Day 3 Review for the quarter SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
Today Quiz not yet graded (Sorry!) More on Multithreading Happens-Before in Java Other langauges with Happens-Before Happens-Before in C++ SE-2811 Slide.
CS2910 Week 7, Class 1 Today Capturing SMTP with Thunderbird Tomorrow Extra office hour at 11 am (right after lab) Friday Office hour cancelled SE-2811.
Java Threads 1 1 Threading and Concurrent Programming in Java Threads and Swing D.W. Denbo.
Week 6, Class 3: Composite Swing composites File composites Computer composites SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors:
Concurrent Programming in Java Based on Notes by J. Johns (based on Java in a Nutshell, Learning Java) Also Java Tutorial, Concurrent Programming in Java.
Week 8, Class 3: Model-View-Controller Final Project Worth 2 labs Cleanup of Ducks Reducing coupling Finishing FactoryMethod Cleanup of Singleton SE-2811.
Week 4, Day 1: Singleton(s?) Singleton leftover Why singletons? How to make lazy initialization work multi- threaded? Observers Why observers? Class structure.
SE3910 Week 8, Class 2 Week 4 Lab: Please return your graded Lab 4 to me so I can enter it in my gradebook Week 7, Class 2 (Wednesday) Half-Exam 2 Done.
Java Thread Programming
Slide design: Dr. Mark L. Hornick
Slide design: Dr. Mark L. Hornick
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
Slide design: Dr. Mark L. Hornick
The Singleton Pattern SE-2811 Dr. Mark L. Hornick.
SE-2811 Software Component Design
Slide design: Dr. Mark L. Hornick
SE /11/2018 If you think the internet is not working in its current incarnation, you can’t change the system through think-pieces and F.C.C. regulations.
Week 6, Class 2: Observer Pattern
Week 7, Class 1: The Command Pattern (cont.)
Google Calendar Appointments
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
9. Threads SE2811 Software Component Design
Slide design: Dr. Mark L. Hornick
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
Polling vs. Interrupts CS2852 4/9/2019
Slide design: Dr. Mark L. Hornick
Slide design: Dr. Mark L. Hornick
Polling vs. Interrupts CS2852 4/21/2019
SE-1021 Software Engineering II
Slide design: Dr. Mark L. Hornick
Slide design: Dr. Mark L. Hornick
Slide design: Dr. Mark L. Hornick
9. Threads SE2811 Software Component Design
Week 8, Class 3: Model-View-Controller
Slide design: Dr. Mark L. Hornick
Slide design: Dr. Mark L. Hornick
Slide design: Dr. Mark L. Hornick
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
SE-1021 Software Engineering II
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
CMSC 202 Threads.
9. Threads SE2811 Software Component Design
Slide design: Dr. Mark L. Hornick
Presentation transcript:

Slide design: Dr. Mark L. Hornick SE-2811 6/4/2018 Week 3, Day 1: Threads Muddiest Point Balancing load Transferring tasks to the Event Dispatch Thread Transferring tasks between threads manually? SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder Dr. Yoder

Questions on Lab? I've received some good ones by email SE-2811 Dr. Mark L. Hornick

Threading Muddiest Point SE-2811 6/4/2018 Threading Muddiest Point Notify() Is it always the same thread until it has nothing to do? notify() who? Why do the threads jump out of order in your example program? Why doesn't it go thread 1 then 2 then 3? Is there a way to even the load so all 3 threads finish at the same time? even loading? More thread examples more examples Nothing SE-2811 Dr. Mark L. Hornick Dr. Yoder

Threading Muddiest Point SE-2811 6/4/2018 Threading Muddiest Point Everything seemed pretty straightforward today Will we learn about more ways to use threads? more examples What is synchronizing "best practice"? best practice None. How do all three threads know that they can leave the method if another thread doesn't come through and notify() them? leaving the method In what other ways can multi threading be used for? Have a great weekend! hope you did too! SE-2811 Dr. Mark L. Hornick Dr. Yoder

Synchronizing Best Practice SE-2811 6/4/2018 Synchronizing Best Practice Unless you KNOW that code will be used multi-threaded, don't synchronize it (Vector vs ArrayList) If a variable will be accessed by multiple threads, synchronize every access to that variable If one thread must wait on another thread's result, synchronize that thread. SE-2811 Dr. Mark L. Hornick Dr. Yoder

Wait and Notify… wait() --- stop here until notified SE-2811 6/4/2018 Wait and Notify… wait() --- stop here until notified notify() --- notify a waiting thread that it can continue notifyAll() – wakes up all waiting threads Like most threading methods notify() does not guarantee that any given thread will start next. Details: http://www.artima.com/insidejvm/ed2/threadsynch.html SE-2811 Dr. Mark L. Hornick Dr. Yoder

Multi-threading in Swing SE-2811 6/4/2018 Multi-threading in Swing The Single-Thread Rule Once a Swing component has been realized, all code that might affect or depend on the state of that component should be executed in the event-dispatching thread. -- Sun Tutorial “Threads in Swing,” Way Back Machine What events should be handled by the event dispatching thread? SE-2811 Dr. Mark L. Hornick Dr. Yoder

Multi-threading in Swing SE-2811 6/4/2018 Multi-threading in Swing “A Swing component that's a top-level window is realized by having one of these methods invoked on it: setVisible(true) show() /** Deprecated */ pack() From the “Obsolete” Java Swing Tutorial http://www.it.cas.cz/manual/java/uiswing/mini/threads.html SE-2811 Dr. Mark L. Hornick Dr. Yoder

Lambda Expression Syntax SE2811 6/4/2018 Lambda Expression Syntax Exercise: What parts does a regular method have? Lambda Expression: A variety of syntaxes are available: <arguments> -> <method body> (Scanner in) -> {int x = in.nextInt(); return x+1;} (int x) -> x+1 () -> System.out.println(“hi”) x -> x+1 SE-2811 Dr. Mark L. Hornick Dr. Josiah Yoder

SE-2811 6/4/2018 http://stackoverflow.com/questions/9218709/multiple-threads-accessing-same-multi-dimensional-array I have been programming C# for 10 months now. I am now learning multi-threading and seems to be working nicely. I have multi-dimension array like string[,] test = new string[5, 13]; I have the threads calling methods that end up saving their outputs to different coordinates inside the array above, without any one thread writing to the same location as another thread. So thread1 might write to test[1,10] but no other thread will ever write to test[1,10] My question is: I have read about using locks on objects like my array, do I have to worry at all about locks even though my threads might access to the test array at the same time but never write to the same coordinates(memory location)? So far in my testing I have not had any issues, but if someone more seasoned than myself knows I could have issue then I'll look into use locks. To best answer this question requires advanced knowledge of writing lock-free code. That will have to wait for another class… SE-2811 Dr. Mark L. Hornick Dr. Yoder

What would you answer? string[,] test = new string[5, 13]; SE-2811 6/4/2018 What would you answer? string[,] test = new string[5, 13]; thread1 might write to test[1,10] but no other thread will ever write to test[1,10] do I have to worry at all about locks? SE-2811 Dr. Mark L. Hornick Dr. Yoder

https://www.polleverywhere.com/free_text_polls/zIp2tH2IVWjXv4H SE-2811 6/4/2018 Muddiest Point SE-2811 Dr. Mark L. Hornick Dr. Yoder