Slide design: Dr. Mark L. Hornick

Slides:



Advertisements
Similar presentations
Slides prepared by Rose Williams, Binghamton University ICS201 Exception Handling University of Hail College of Computer Science and Engineering Department.
Advertisements

Week 9, Class 3: Model-View-Controller Final Project Worth 2 labs Happens-Before ( SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors:
More Multithreaded Programming in Java David Meredith Aalborg University.
Threading in Java – a Tutorial QMUL IEEE SB. Why Threading When we need to run two tasks concurrently So multiple parts (>=2) of a program can run simultaneously.
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.
Multithreading in Java Project of COCS 513 By Wei Li December, 2000.
Week 3, Day 1: Processes & Threads Processes Threads SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
Today’s Agenda  Quick Review  Finish Java Threads  The CS Problem Advanced Topics in Software Engineering 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.
Multithreading in Java Sameer Singh Chauhan Lecturer, I. T. Dept., SVIT, Vasad.
OPERATING SYSTEMS Frans Sanen.  Recap of threads in Java  Learn to think about synchronization problems in Java  Solve synchronization problems in.
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.
Dr. R R DOCSIT, Dr BAMU. Basic Java :Multi Threading Cont. 2 Objectives of This Session Explain Synchronization in threads Demonstrate use of.
15.1 Threads and Multi- threading Understanding threads and multi-threading In general, modern computers perform one task at a time It is often.
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.
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.
Today Return Quiz First release of final project template Multithreading Options Qt socket buffers between threads Tomorrow: Quiz Interthread communication.
CE1901 Week 6, Class 3 Week 6 Mini-Exam Review Muddiest Point Timing Diagrams (See this slide and Outcomes on course webpage – link now available)Outcomes.
Week 9, Class 3: Java’s Happens-Before Memory Model (Slides used and skipped in class) SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors:
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:
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.
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.
Java Thread Programming
Tutorial 2: Homework 1 and Project 1
Multithreading / Concurrency
Slide design: Dr. Mark L. Hornick
Multi Threading.
Slide design: Dr. Mark L. Hornick
Week 2, Day 1: The Factory Method Pattern
The Singleton Pattern SE-2811 Dr. Mark L. Hornick.
SE-2811 Software Component Design
Lecture 21 Concurrency Introduction
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
Looping and Repetition
Week 7, Class 1: The Command Pattern (cont.)
Multithreading.
Multithreading.
Dr. Mustafa Cem Kasapbaşı
Java Concurrency 17-Jan-19.
Synchronized Threads and Threads Coordination
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
9. Threads SE2811 Software Component Design
Java Concurrency.
NETWORK PROGRAMMING CNET 441
Polling vs. Interrupts CS2852 4/21/2019
SE-1021 Software Engineering II
Java Concurrency.
Threads and Multithreading
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
Java Concurrency 29-May-19.
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
CMSC 202 Threads.
9. Threads SE2811 Software Component Design
Presentation transcript:

Slide design: Dr. Mark L. Hornick SE-2811 6/4/2018 Week 2, Day 3: Threads Synchronization Questions SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder Dr. Yoder

The synchronized statement synchronized(variable) { variable.get(…) // only one of these } variable.set(…) // statements can be variable = new V() // executed at a time… SE-2811 Dr. Mark L. Hornick

What is the difference between SE-2811 6/4/2018 What is the difference between public synchronized void myMethod() { // … } and public void myMethod() { synchronized (this) { } ? SE-2811 Dr. Mark L. Hornick Dr. Yoder

SE-2811 6/4/2018 http://www.cs.cornell.edu/andru/javaspec/17.doc.html The synchronized statement (§14.17) computes a reference to an object; it then attempts to perform a lock action on that object and does not proceed further until the lock action has successfully completed. ... SE-2811 Dr. Mark L. Hornick Dr. Yoder

SE-2811 6/4/2018 http://www.cs.cornell.edu/andru/javaspec/17.doc.html A synchronized method (§8.4.3.5) automatically performs a lock action when it is invoked… If the method is an instance method, it locks the lock associated with the instance for which it was invoked (… “this” …). If the method is static, it locks the lock associated with the Class object that represents the class in which the method is defined. ... SE-2811 Dr. Mark L. Hornick Dr. Yoder

Conclusion: public synchronized void myMethod() SE-2811 6/4/2018 Conclusion: public synchronized void myMethod() And synchronized (this) { // … } are the same public static synchronized void myMethod() synchronized (SomeClass.class) { // … } Are the same SE-2811 Dr. Mark L. Hornick Dr. Yoder

Is it safe to have multiple blocks access the same data? SE-2811 6/4/2018 Is it safe to have multiple blocks access the same data? See e.g. “The synchronized statement (§14.17) computes a reference to an object; it then attempts to perform a lock action on that object” Yes or No? SE-2811 Dr. Mark L. Hornick Dr. 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. 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

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

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