L23cs211sp07-6up - Threads and Concurrency Lecture 23 CS211...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Threads and Concurrency Lecture 23 CS211 Spring 2007 Announcements ACSU final general meeting of the year Wed 4/25, 5pm, Upson Lounge (117) Speaker: Gun Sirer on P2P networks Free food! Online course evaluations are available from now until next Monday noon please visit http://www.engineering.cornell.edu/CourseEval/ What is a Thread? A separate process that can perform a computational task independently and concurrently with other threads Most programs have only one thread GUIs have a separate thread, the event dispatching thread A program can have many threads You can create new threads in Java What is a Thread? In reality, threads are an illusion The processor shares its time among all the active threads Implemented with support from underlying operating system or virtual machine Gives the illusion of several threads running simultaneously Concurrency (aka Multitasking) Refers to situations in which several threads are running simultaneously Special problems arise race conditions deadlock The operating system provides support for multitasking In reality there is one processor doing all this But this is an illusion too at the hardware level, lots of multitasking memory subsystem video controller buses instruction prefetching Threads in Java Threads are instances of the class Thread can create as many as you like The Java Virtual Machine permits multiple concurrent threads initially only one thread (executes main ) Threads have a priority higher priority threads are executed preferentially a newly created Thread has initial priority equal to the thread that created it (but can change) Creating a new Thread (Method 1) class PrimeThread extends Thread { long a, b; PrimeThread( long a, long b) { this .a = a; this .b = b; } public void run() { //compute primes between a and b ... } } PrimeThread p = new PrimeThread(143, 195); p.start(); overrides Thread.run() can call run() directly calling thread will run it or, can call start() will run run() in new thread Creating a new Thread (Method 2) class PrimeRun implements Runnable { long a, b; PrimeRun( long a, long b) { this .a = a; this .b = b; } public void...
View Full Document

This note was uploaded on 11/20/2008 for the course COM S 211 taught by Professor Kozen during the Spring '06 term at Cornell University (Engineering School).

Page1 / 4

L23cs211sp07-6up - Threads and Concurrency Lecture 23 CS211...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online