Concurrency in First Year Judith Bishop University of Pretoria South Africa www.cs.up.ac.za/~jbishop.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Multiplexing/Demux. CPSC Transport Layer 3-2 Multiplexing/demultiplexing application transport network link physical P1 application transport network.
Java Applets- Using SwingWorker Dave Price and Chris Loftus Computer Science Department University of Wales, Aberystwyth.
Sockets For Servers Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University.
Java Threads Part I. Lecture Objectives To understand the concepts of multithreading in Java To be able to develop simple multithreaded applications in.
1 Java - Threads A thread is an individual flow of control within a larger program. A program which is running more than one thread is said to be multithreaded.
A CHAT CLIENT-SERVER MODULE IN JAVA BY MAHTAB M HUSSAIN MAYANK MOHAN ISE 582 FALL 2003 PROJECT.
CSE S. Tanimoto Java Threads 1 Java Threads (Outline) Motivation The class Thread Example program: ThreadRace The Runnable interface Example: Clock.
22-Jun-15 Threads and Multithreading. 2 Multiprocessing Modern operating systems are multiprocessing Appear to do more than one thing at a time Three.
Starts to load image Delay on network Load some more of the image Time for some word processing Thread 2 Thread 1 Figure 15.1 Two threads sharing the processor.
Slides prepared by Rose Williams, Binghamton University ICS201 Lectures 18 : Threads King Fahd University of Petroleum & Minerals College of Computer Science.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
29-Jun-15 Threads and Multithreading. 2 Multiprocessing Modern operating systems are multiprocessing Appear to do more than one thing at a time Three.
Multithreading in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Java, Java, Java Object Oriented Problem Solving Chapter 13: Threads and Concurrent Programming.
Threads II. Review A thread is a single flow of control through a program Java is multithreaded—several threads may be executing “simultaneously” If you.
More Multithreaded Programming in Java David Meredith Aalborg University.
Web Proxy Server. Proxy Server Introduction Returns status and error messages. Handles http CGI requests. –For more information about CGI please refer.
19-Aug-15 About the Chat program. 2 Constraints You can't have two programs (or two copies of the same program) listen to the same port on the same machine.
Io package as Java’s basic I/O system continue’d.
A Bridge to Your First Computer Science Course Prof. H.E. Dunsmore Concurrent Programming Threads Synchronization.
Computer Science II 810:062 Section 01 Session 2 - Objects and Responsibilities.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
Welcome to CIS 083 ! Events CIS 068.
Object Oriented Programming Lecture 8: Introduction to laboratorial exercise – part II, Introduction to GUI frames in Netbeans, Introduction to threads.
CS12420 – Swing and threads Lynda Thomas
Chapter 34 Java Technology for Active Web Documents methods used to provide continuous Web updates to browser – Server push – Active documents.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Practicum: - Client-Server Computing in Java Fundamental Data Structures and Algorithms Margaret Reid-Miller 13 April 2004.
1 Web Based Programming Section 8 James King 12 August 2003.
1 Chapter 28 Networking. 2 Objectives F To comprehend socket-based communication in Java (§28.2). F To understand client/server computing (§28.2). F To.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae, VUW Networking COMP # 22.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Networking and Concurrency COMP.
CS390- Unix Programming Environment CS 390 Unix Programming Environment Java Socket Programming.
Networks and Client/Server Applications Handling Multiple Clients Concurrently.
12/5/00SEM107, Kamin & ReddyReview - 34 Events Event types Catching different event types Getting information from components and events Distinguishing.
Concurrent Programming and Threads Threads Blocking a User Interface.
Session 16 Pinball Game Construction Kit:. Pinball Version 1 Replaced the fire button with a mouse event. Multiple balls can be in the air at once. –Uses.
Multithreading in Java Sameer Singh Chauhan Lecturer, I. T. Dept., SVIT, Vasad.
Li Tak Sing COMPS311F. RMI callbacks In previous example, only the client can initiate a communication with the server. The server can only response to.
Multi-Threading in Java
Threads in Java Threads Introduction: After completing this chapter, you will be able to code your own thread, control them efficiently without.
Threads and Multithreading. Multiprocessing Modern operating systems are multiprocessing Appear to do more than one thing at a time Three general approaches:
Network Programming: Servers. Agenda l Steps for creating a server Create a ServerSocket object Create a Socket object from ServerSocket Create an input.
Java Threads 1 1 Threading and Concurrent Programming in Java Threads and Swing D.W. Denbo.
Chapter 11: Threaded Programs Situations where the program is following multiple execution paths (how to stop one?) Thread: a line of execution Thread.
CS 1 with Robots CS1301 – Where it Fits Institute for Personal Robots in Education (IPRE)‏
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
Networks and Client/Server Applications
Threads and Multithreading
Object-Orientated Analysis, Design and Programming
PC02 Term 1 Project Basic Messenger. PC02 Term 1 Project Basic Messenger.
Clients and Servers 19-Nov-18.
Threads and Multithreading
Clients and Servers 1-Dec-18.
Threads and Multithreading
Threads and Multithreading
Threads and Multithreading
Threads and Multithreading
Threads and Multithreading
Threads and Multithreading
Threads and Multithreading
Threads.
Clients and Servers 19-Jul-19.
Clients and Servers 13-Sep-19.
Presentation transcript:

Concurrency in First Year Judith Bishop University of Pretoria South Africa

Background n 500 students in Science, Maths, Engineering, Commerce and Arts n Prior intro to programming at K12 level or a one semester Pascal or C course n Java introduced in 1998 as lingua franca n Semester 1 – concentrates on oops, event-driven programming, applets and URL resources n Semester 2 – concentrates on multithreading, sockets, (plus computer “know how”, data structures and algorithms)

What kind of concurrency? n Multithreading n User interfacing –e.g. one thread watches the buttons, one does the animation n Many instances –e.g. viewing multiple yet independent copies of animations n Networking n Access to URL resources –primarily for images n Inter-socket connections –message passing

Animation and multiple threads example

Program structure

The run method public void run() { while (true) { for (int light = 0; light < 3; light++) { if (light == red & walk) { walkOn = false; for (int i = 0; i < 11; i++) { draw(light); try { sleep(time[3]);} catch (InterruptedException e) { } walkOn = !walkOn; } walk = false; } else { draw(light); try { sleep(time[light]); } catch (InterruptedException e) { } }

ActionPerformed public void actionPerformed(ActionEvent e) { Object event = e.getSource(); if (event == newSetButton) { lights[nLights] = new SetOfLights(area, lightsPosition); lights[nLights].start(); lightsPosition += lightsWidth; nLights++; if (nLights == 3) newSetButton.setEnabled(false); Each time the NewSet button is pressed, a new thread is created. The thread references are stored in an array.

The Mars Lander example

The run method public void run () { while (calc.s > 0 && !endthread) { try {sleep (500); calc.integrate (); draw(); } catch (InterruptedException e) {} } if (!endthread) if (calc.v < -10) drawEnd(crasher, "You have crash-landed on Mars"); else drawEnd(lander, "Congratulations: “+ “you have landed safely on Mars"); }

A URL resource example

A Socket example – ATM machine ServerSocket listener = new ServerSocket(port); int c = 0; while (!done) { // This is where the program waits Socket client = listener.accept( ); c ++; System.out.println("Card inserted on " + client.getInetAddress().getHostName()); System.out.println("Starting a new “+ “client, numbered "+c); new handler(client, c).start(); } listener.close();

A typical exam question c)Write a method called readPicture which gets a URL name from a text field and tries to return the image at that location for three tries, after which it returns a null image reference instead. (Hint: the statement to get an image is: f.createImage((ImageProducer) imagename.getContent()); and it throws an ImageException if unsuccessful). (4)

Concurrency in Java n comes in several guises (and levels) n is easy at the non-synchronised levels n enables students to create wonderful animations and interactive programs with little fuss Conclusion n We see threads as no more complex or less essential than than event listeners n We bring them into first year as and when needed by the applications being discussed