Threads Load new page Page is loading Browser still responds to user (can read pages in other tabs)

Slides:



Advertisements
Similar presentations
13/04/2015Client-server Programming1 Block 6: Threads 1 Jin Sa.
Advertisements

Chap 4 Multithreaded Programming. Thread A thread is a basic unit of CPU utilization It comprises a thread ID, a program counter, a register set and a.
1 Chapter 5 Threads 2 Contents  Overview  Benefits  User and Kernel Threads  Multithreading Models  Solaris 2 Threads  Java Threads.
Modified from Silberschatz, Galvin and Gagne ©2009 Lecture 7 Chapter 4: Threads (cont)
Threads Load new page Page is loading Browser still responds to user (can read pages in other tabs)
Threads Section 2.2. Introduction to threads A thread (of execution) is a light-weight process –Threads reside within processes. –They share one address.
Java Threads Part II. Lecture Objectives To understand the concepts of multithreading in Java To be able to develop simple multithreaded applications.
CSE S. Tanimoto Java Threads 1 Java Threads (Outline) Motivation The class Thread Example program: ThreadRace The Runnable interface Example: Clock.
CS220 Software Development Lecture: Multi-threading A. O’Riordan, 2009.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
1 Chapter 4 Threads Threads: Resource ownership and execution.
Multithreading in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
A. Frank - P. Weisberg Operating Systems Introduction to Tasks/Threads.
Java Threads CS Introduction to Operating Systems.
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Multithreading in Java Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
ThreadsThreads operating systems. ThreadsThreads A Thread, or thread of execution, is the sequence of instructions being executed. A process may have.
Multithreading.
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.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
Chapter 4: Threads Adapted to COP4610 by Robert van Engelen.
9/13/20151 Threads ICS 240: Operating Systems –William Albritton Information and Computer Sciences Department at Leeward Community College –Original slides.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Silberschatz, Galvin and Gagne ©2011Operating System Concepts Essentials – 8 th Edition Chapter 4: Threads.
1 CSCE3193: Programming Paradigms Nilanjan Banerjee Programming Paradigms University of Arkansas Fayetteville, AR
Computer Engineering Rabie A. Ramadan Lecture 8. Agenda 2 Introduction Thread Applications Defining Threads Java Threads and States Priorities Accessing.
Contacts and Calendars  PIM API (Personal Information Management)  Flexible framework for access to:  Contact list  Calendar list  To-Do list.
1 Web Based Programming Section 8 James King 12 August 2003.
CS 346 – Chapter 4 Threads –How they differ from processes –Definition, purpose Threads of the same process share: code, data, open files –Types –Support.
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
A Guide to Advanced Java Faculty:Nguyen Ngoc Tu. Concurrent programming in Java How to make all things run-able?
Source: Operating System Concepts by Silberschatz, Galvin and Gagne.
Multithreading in Java Sameer Singh Chauhan Lecturer, I. T. Dept., SVIT, Vasad.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Chapter 6 (6.7 & 6.9 only) - Threads & Mutex Threads –A Thread is a basic unit of CPU utilization consisting of a program counter, register set and stack.
1 Lecture 4: Threads Advanced Operating System Fall 2010.
Chapter 4: Threads. 2 Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads.
Introduction to Threads Session 01 Java Simplified / Session 14 / 2 of 28 Objectives Define a thread Define multithreading List benefits of multithreading.
Java Thread and Memory Model
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Threads Overview Multithreading Models Threading Issues.
Multithreaded Programing. Outline Overview of threads Threads Multithreaded Models  Many-to-One  One-to-One  Many-to-Many Thread Libraries  Pthread.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Multi-Threading in Java
Parallel Processing (CS526) Spring 2012(Week 8).  Shared Memory Architecture  Shared Memory Programming & PLs  Java Threads  Preparing the Environment.
1 OS Review Processes and Threads Chi Zhang
Threads. Readings r Silberschatz et al : Chapter 4.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-2: Threads Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
CISC2200 Threads Fall 09. Process  We learn the concept of process  A program in execution  A process owns some resources  A process executes a program.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads  Overview  Multithreading Models  Threading Issues  Pthreads.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Threads prepared and instructed by Shmuel Wimer Eng. Faculty, Bar-Ilan University 1July 2016Processes.
Introduction to threads
Multi Threading.
Lecture 9 Object Oriented Programming Using Java
PA1 Discussion.
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Distributed Systems - Comp 655
Chapter 4: Threads.
Mid Term review CSC345.
Java Threads (Outline)
Threads Chapter 4.
Java Threads (Outline)
Java Thread.
Gentle Introduction to Threads
Chapter 4: Threads.
CS Introduction to Operating Systems
Presentation transcript:

Threads Load new page Page is loading Browser still responds to user (can read pages in other tabs)

Threads  Advantages  some tasks inherently parallel – can exploit the underlying architecture  responsive applications – user can still use application while operation pending  sharing of resources (communication) is easier  switching between threads is faster than process switching  overhead in creating threads is small

Threads Single-threaded process Global DataFiles, I/O RegistersStack thread Multi-threaded process Global DataFiles, I/O Registers Stack Registers Stack Registers Stack

Java thread States newrunnabledead blocked new start() exits run() method wait for I/O (file, input) I/O available

Creating Threads  Extend the Thread class, override run() method class FetchThread extends Thread { private String url; public FetchThread(String url) { this.url = url; } public void run() { // 1. connect to server // 2. download page // 3. update view widget } // LATER ON... Thread fetch = new FetchThread(“ fetch.start();

Creating Threads  Implement Runnable interface (only one method run()) class FetchThread implements Runnable { private String url; public FetchThread(String url) { this.url = url; } public void run() { // 1. connect to server // 2. download page // 3. update view widget } // LATER ON... Runnable target = new FetchThread(“ Thread fetch = new Thread(target); fetch.start();

MIDlets and Threads (I) class DemoMIDlet implements CommandListener, Runnable { public void run() { if (lastCmd == addCmd) { // handle add operation } else if (lastCmd == showCmd) { // handle show operation } public void commandAction(Command c, Displayable d) { Form ackForm = new Form(“Working...”); display.setCurrent(ackForm); Thread t = new Thread(this); t.start(); }

MIDlets and Threads (II) class DemoMIDlet implements CommandListener, Runnable { class UpdateThread implements Runnable { Command lastCmd; public void UpdateThread(Command c) { lastCmd = c; } public void run() { if (lastCmd == addCmd) { // handle add operation } public void commandAction(Command c, Displayable d) { Form ackForm = new Form(“Working...”); display.setCurrent(ackForm); Thread t = new Thread(new UpdateThread(c)); t.start(); }

Demo

Taking Pictures  Setting up the Control player = Manager.createPlayer("capture://video"); player.realize(); videoControl = (VideoControl) player.getControl("VideoControl"); Form form = new Form("Camera Form"); Item item = (Item) videoControl.initDisplayMode( GUIControl.USE_GUI_PRIMITIVE, null); form.append(item); mDisplay.setCurrent(form);  Taking the picture byte[] raw = videoControl.getSnapshot(null); Image image = Image.createImage(raw, 0, raw.length);

Taking Pictures  Permissions javax.microedition.media.control.RecordControl javax.microedition.media.control.VideoControl.getSnapshot