java-concurrency-tut3-6up

Course: CMSC 433, Spring 2001
School: Maryland
Rating:
 
 
 
 
 

Word Count: 1255

Document Preview

COOTS USENIX '98 April 27, 1998 Optimistic Policies: Trying Isolate state into versions E.g. by grouping into a helper class Isolate state changes to atomic commit method that swaps in new state On method entry Save/record current state Apply action to new state Only commit if Action succeeds and current state version is unchanged If can't commit: fail or retry Failures are clean (no side effects) Retry policy...

Register Now

Unformatted Document Excerpt

Coursehero >> Maryland >> Maryland >> CMSC 433

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
COOTS USENIX '98 April 27, 1998 Optimistic Policies: Trying Isolate state into versions E.g. by grouping into a helper class Isolate state changes to atomic commit method that swaps in new state On method entry Save/record current state Apply action to new state Only commit if Action succeeds and current state version is unchanged If can't commit: fail or retry Failures are clean (no side effects) Retry policy is variation of a busy-wait Only applicable if actions fully reversible No I/O or thread construction unless safely cancellable All internally called methods must be undoable 2003 David Holmes and Doug Lea Specifying Policies Some policies are per-type Optimistic approaches require all methods to conform Some policies can be specified per-call Balking vs. Guarding vs. Guarding with time-out Options for specifying per-call policy: Extra parameters void put(Object x, long timeout ) void put(Object x, boolean balk ) Different name for balking or guarding boolean tryPut( Object x ) // balking void put( Object x ) // guarding May need different exception signatures 95 2003 David Holmes and Doug Lea 98 Optimistic Techniques Variations for recording versions of mutable data: Immutable helper classes Version numbers Transaction Ids Time-stamps May be more efficient than guarded waits when: Conflicts are rare and when running on multiple CPUs Retries can livelock unless proven wait-free Analog of deadlock in guarded waits Should arrange to fail after a certain time or number of attempts Thread Creation Patterns Three general sets of patterns for introducing concurrency: Autonomous loops Establishing independent cyclic behaviour Oneway messages Sending messages without waiting for reply or termination Improves availability of sender object Interactive messages (not covered--see CPJ) Requests that later result in reply or callback messages Allows client to proceed concurrently for a while Most design ideas and semantics stem from active object models 2003 David Holmes and Doug Lea 2003 David Holmes and Doug Lea 96 99 Optimistic Bounded Counter public class OptimisticBoundedCounter { private final long MIN, MAX; private Long count; // MIN <= count <= MAX public OptimisticBoundedCounter(long min, long max) { MIN = min; MAX = max; count = new Long(MIN); } public long value() { return count().longValue(); } public synchronized Long count() { return count;} private synchronized boolean commit(Long oldc, Long newc) { boolean success = (count == oldc); if (success) count = newc; return success; } public void inc() throws InterruptedException{ for (;;) { // retry-based if (Thread.interrupted()) throw new InterruptedException(); Long c = count(); // record current state long v = c.longValue(); if (v < MAX && commit(c, new Long(v+1))) break; Thread.yield(); // a good idea in spin loops } } public void dec() { /* symmetrical */} } 2003 David Holmes and Doug Lea Autonomous Loops Simple non-reactive active objects contain a run loop of form: public void run() { while (!Thread.interrupted()) doSomething(); } Normally established with a constructor containing: new Thread(this).start(); Or by a specific start method Perhaps also setting priority and daemon status Normally also support other methods called from other threads Requires standard safety measures Common Applications Animations, Simulations, Message buffer Consumers, Polling daemons that periodically sense state of world This is the basic approach of our web server so far 97 2003 David Holmes and Doug Lea 100 Designing Concurrent Object-Oriented Programs in Java 1 USENIX COOTS '98 April 27, 1998 Oneway Messages Design Goals for Oneway Messages Safety Local state changes should be atomic (normally, locked) Typical need for locking leads to main differences vs singlethreaded Event systems Safe guarding and failure policies, when applicable Availability Conceptually oneway messages are sent with No need for replies No concern about failure (exceptions) No dependence on termination of called method No dependence on order that messages are received But may sometimes want to cancel messages or resulting activities Once oneway message has been sent, host is ready to accept the next message 2003 David Holmes and Doug Lea Minimize delay until host can accept another message Flow The activity should progress with minimal contention Performance Minimize overhead and resource usage Introducing threads is not always the best solution Consider just issuing open calls 101 2003 David Holmes and Doug Lea 104 Oneway Message Styles Thread Patterns for Oneway Messages Some semantic choices Asynchronous: Entire message send is independent By far, most common style in applications reactive Synchronous: Caller must wait until message is accepted Basis for rendezvous protocols Multicast: Message is sent to group of recipients The group might not even have any members 2003 David Holmes and Doug Lea 102 2003 David Holmes and Doug Lea 105 Messages in Java Direct method invocations Rely on standard call/return mechanics Command strings Recipient parses then dispatches to underlying method Widely used in client/server systems including HTTP EventObjects and service codes Recipient dispatches Widely used in GUIs, including AWT Request objects, asking to perform encoded operation Used in distributed object systems -- RMI and CORBA Class objects (normally via .class files) Recipient creates instance of class Used in Java Applet framework Runnable commands Basis for thread instantiation, mobile code systems 2003 David Holmes and Doug Lea Threads-Per-Message Web Server Return to one-shot version of startServer but pass each accepted connection to a new thread for processing: // WebServer14.java Thread serverThread; public synchronized void startServer() throws ... { if (serverThread != null) throw new IllegalStateException("Already started"); serverThread = new Thread(new ConnectionHandler()); serverThread.start(); } private class ConnectionHandler implements Runnable { public void run() { // ... try { while (!Thread.interrupted()) { RequestHandler r = new RequestHandler(server.accept()); new Thread(r, "worker-thread").start(); } } catch (InterruptedIOException ex) { /* ignore */ } catch (IOException ex) { /* report */ } } } 103 2003 David Holmes and Doug Lea 106 Designing Concurrent Object-Oriented Programs in Java 2 USENIX COOTS '98 April 27, 1998 Thread-Per-Message Web Server (cont...) private class RequestHandler implements Runnable { private final Socket sock; public RequestHandler(Socket sock) { this.sock = sock; } public void run() { try { processRequest(sock); } catch (Throwable t) { /* report */ } } } Channel Options Unbounded queues Can exhaust resources if clients faster than handlers Bounded buffers Can cause clients to block when full Synchronous channels Force client to wait for handler to complete previous task Leaky bounded buffers For example, drop oldest if full Priority queues Run more important tasks first Streams or sockets Enable persistence, remote execution Non-blocking channels Must take evasive action if put or take fail or time out 2003 David Holmes and Doug Lea Shutdown process simplified: only one thread uses ServerSocket public void shutdownServer() throws InterruptedException, IllegalStateException, IOException { synchronized (this) { if (shutdownInitiated) throw new IllegalStateException("Shutdown performed"); if (serverThread == null) throw new IllegalStateException("Serv...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

Maryland - CMSC - 433
Iteration CMSC 433 Programming Language Technologies and Paradigms Fall 2003Iterators and Design Patterns September 25, 2003 Goal: Loop through all objects in an aggregateclass Node { Element elt; Node next; } Node n = .; while (n != null) { .; n
Maryland - CMSC - 433
Administrivia CMSC 433 Programming Language Technologies and Paradigms Spring 2005Iterators and Design Patterns February 15, 2005 Other resources: Thinking in Patterns with Java Link from the class web page Gamma, Helm, Johnson, Vlissides, Des
Maryland - CMSC - 714
Sisal FAQThe Sisal Model of Functional Programming and its Implementation Jean-Luc Gauditot, et al. Presented by Nick RutarWhat does Sisal stand for?Stream and Iteration in a Single Assignment LanguageWhat kind of language is it?Sisal is a func
Maryland - CMSC - 250
Predicate Calculus Subject / Predicate John / went to the store. The sky / is blue. Propositional Logic - uses statements Predicate Calculus - uses predicates predicates must be applied to a subject in order to be true or falseQuantification x
Maryland - CMSC - 631
C ONTEXT- SENSITIVE C ORRELATION A NALYSIS FOR R ACE D ETECTIONPolyvios Pratikakis Jeff Foster Michael Hicks University of Maryland, College ParkContext-sensitive Correlation Analysis for Detecting Races p.1/28Data RacesRace: two threads acces
Maryland - CMSC - 433
(Incomplete) History of GUIsCMSC 433 Programming Language Technologies and Paradigms Spring 2004 1973: Xerox Alto 3-button mouse, bit-mapped display, windows 1981: Xerox Star Double-clicking, overlapping windows, dialogsGraphical User Interf
Maryland - PHYS - 122
Physics 122Final Exam 2 p. 2Name_ Section_Just the answer counts for these. (8 points each) 1) Two little beads have charges on them, q and 2q, a distance d apart. What is the strength and direction of the electric field at a point I marked X
Maryland - HONR - 278
LSU - PHYS - 2102
LSU - APPL - 003
Car reers2Geaux SignUpforO S OnCampusIn nterviewsCareers2Geau C ux SignUpforOnCampus sInterviews TWWW.LSU.EDU/CAREER VISIT Clic ckCareers2Ge eaux. Log ginorcreatea anaccount. TOPNAVIGATIO ONBAR) HOVEROVERMYACCOUNT(T Clic ckMyProfile. Ma ak
LSU - EXST - 7005
EXPERIMENTAL STATISTICS 7005 April 15, 1999NAME _ EXAM 3 All sections : GeaghanRead Carefully. Give an answer in the form of a number or numeric expression where possible. Show all calculations for possible partial credit. Use a value of 0.05 for
LSU - EXST - 7025
1000 900 800Mortality over timeFish Stock Stock700Nt 600500 400 Fishing mortality 300 200 Total mortality 100 0 0 5 10 15 20 25 30 Natural mortalityTime1600 1400 1200Catch per boat dayN0Leslie modelCatch per unit of effortLesli
LSU - EXST - 7005
Outline1) Continuous random variable 2) Uniform distribution 3) Normal distribution 4) Normal approximation of binomial distributionEXST7005 - Statistical Techniques I1Continuous Random Variable A continuous RV, X takes values x anywhere RV i
LSU - EXST - 7013
Reference/Additional Material: Simple Linear Regression1 Introduction Regression analysis is a statistical method for analyzing a relationship between two or more variables in such a manner that one variable can be predicted or explained by using th
LSU - EXST - 7013
Categorical Data AnalysisIntroduction In subject areas such as the social and behavioral sciences, we often encounter data in which the possible outcomes are categories. One example of these type of data are eye color (hazel, blue, brown, green), wh
Virginia Tech - ETD - 07212000
On a turbo decoder design for low power dissipationBy Jia Fei Dissertation submitted to the Faculty of the Virginia Polytechnic Institute and State University in partial fulfillment of the requirements for the degree of Master of Science In Electric
Virginia Tech - ETD - 04222003
Interference Measurements and Throughput Analysis for 2.4 GHz Wireless Devices in Hospital EnvironmentsbySeshagiri KrishnamoorthyThesis submitted to the faculty of the Virginia Polytechnic Institute and State University in partial fulfillment of
Virginia Tech - SRS - 4702
A High Performance Micro Channel Interface for Real-Time Industrial Image Processing ApplicationsThomas H. Drayer, Joseph G. Tront, and Richard W. ConnersBradley Department of Electrical Engineering, Virginia Polytechnic Institute and State Univers
Virginia Tech - ETD - 12192000
Factors Influencing Biotite WeatheringbyRyan Ronald Reed Thesis submitted to the Faculty of the Virginia Polytechnic Institute and State University in partial fulfillment of the requirements for the degree of MASTER OF SCIENCE in Crop and Soil Env
LSU - APPL - 003
LSU - PHYS - 2102
LSU - PHYS - 2102
Todays lectureAmperes law, a powerful tool to compute magnetic fields.To compute magnetic fields, one uses the Biot-Savart law:r r r 0 i d s r dB = 4 r 3And it is evident that the Biot-Savart law is harder to use than Coulombs law. Now, even
LSU - PHYS - 7231
January 22, 2009PHYS 7231Homework 2 Due date: January 29, 20091. Calculate a. the components of grad ( r) in spherical polar coordinates, b. div er , grad div er , curl er , div e , curl e in spherical polar coordinates, c. the components of cur
LSU - PHYS - 2101
Formula Sheet for LSU Physics 2101, Summer '07, Exam 3.Units: 1 m = 39.4 in = 3.28 ft 1 rev = 360 = 2 rad 1 mi = 5280 ft 1 atm = 1.013105 Pa 1 min = 60 s 1 N = 0.225 lb 1 day = 24 h 1 atmL = 101.22 J 1 h = 60 minConstants: g = 9.8 m/s2 G = 6.6710-
LSU - PHYS - 2101
Formula Sheet for LSU Physics 2101, Summer 07, Final Exam.Units: 1 m = 39.4 in = 3.28 ft 1 rev = 360 = 2 rad 1K TC + 273.15 K T = 1 C 1 mi = 5280 ft 1 atm = 1.013105 Pa 9 F TF = TC + 32 F 5 C 1 min = 60 s 1 N = 0.225 lb 1 cal = 4.186 J MEarth = 5.98
LSU - PHYS - 2101
Formula Sheet for LSU Physics 2101, Spring 07.Units: 1 m = 39.4 in = 3.28 ft 1 rev = 360 = 2 rad 1K TC + 273.15 K T = 1 C 1 mi = 5280 ft 1 atm = 1.013105 Pa 9 F TF = TC + 32 F 5 C 1 min = 60 s 1 h = 60 min 1 cal = 4.186 J MEarth = 5.981024 kg MM oon
LSU - PHYS - 2101
Week 1 2 2 3 4 5 5 5 6 7 8 9 9 9 10 11 12 12 12 13 14 15 16Dates Aug 28, 30; Sep 1 Sept 5 Sept 6, 8 Sept 11, 13, 15 Sept 18, 20, 22 Sept 25 Sept 26 Sept 27, 29 Oct 2, 4 Oct 9, 11, 13 Oct 16, 18, 20 Oct 23 Oct 24 Oct 25, 27 Oct 30, Nov 1, 3 Nov 6, 8
LSU - PHYS - 2221
Homework 4L. Lehner, Phys 2221 Th March 11th 2007 March 18, 2008Abstract Multiple-variables calculus &amp; Lagrange multipliers.1. Solve from Boas. page 294, problems 1 &amp; 7. 2. Solve from Boas. page 322, problem 2. 3. Solve from Boas. page 334, probl
LSU - PHYS - 7221
Problem Set 1Physics 7221 Fall 2007 Date due: Friday 9/211. Prove that the magnitude R of the position vecotr for the center of mass from an arbitrary origin is given by the equation, M 2 R2 = Mi 2 mi ri 1 2 i,j 2 mi mj rij .2. The force of a
LSU - PHYS - 2101
SID 12 35 55 73 305 327 423 450 856 1095 1582 1720 1956 2165 2234 2367 2527 2784 2908 3036 3141 3170 3232 3324 3428 4086 4299 4308 4679 4929 5397 5476 5483 5654 5667 5956 6033 6075 6075 6125 6177 6402 6547 7163 7276 7291 7386 7469 7594 8135 8304 8394
University of Texas - PSY - 341
1The radiance spectrum of a surface is the product of the reflectance function of the surface and the irradiance spectrum of the light falling on the surface.2Regan et al. (2001)Examples of natural daylight irradiance spectra plotted in relat