Deadlock Victim. dimanche 6 mai 12

Size: px
Start display at page:

Download "Deadlock Victim. dimanche 6 mai 12"

Transcription

1 Deadlock Victim by Dr Heinz Kabutz && Olivier Croisier The Java Specialists Newsletter && The Coder's Breakfast && 1

2 You discover a race condition 2

3 Data is being corrupted 3

4 What ya gonna do? 4

5 Who ya gonna call? 5

6 Ghostbusters? 6

7 you do what we all do 7

8 you use synchronized 8

9 synchronized 9

10 synchronized 9

11 synchronized can be bad medicine 10

12 deadlock awaits you! 11

13 12

14 Deadlock Victim 13

15 Correctness fix can lead to liveness fault 14

16 lock ordering deadlock 15

17 at least two locks 16

18 and at least two threads 17

19 locked in different orders 18

20 can cause a deadly embrace 19

21 requires global analysis to fix 20

22 resource deadlocks 21

23 bounded queues 22

24 bounded thread pools 23

25 semaphores 24

26 class loaders 25

27 lost signals 26

28 The Drinking Philosophers 27

29 @ the Java Specialist Symposium in Crete 28

30 Symposium == sym + poto Literally - to drink together 29

31 our philosophers need two cups 30

32 they either want to drink or think 31

33 Table is ready, all philosophers are thinking

34 philosophers 5 wants to drink, takes right cup

35 Philosopher 5 is now drinking with both cups

36 philosophers 3 wants to drink, takes right cup

37 Philosopher 3 is now drinking with both cups

38 philosophers 2 wants to drink, takes right cup

39 Philosopher 3 finished drinking, returns right cup

40 Philosopher 2 is now drinking with both cups

41 Philosopher 3 returns Left cup

42 philosophers can get stuck 41

43 if they all pick up the right cup 42

44 A deadlock can easily happen with this design

45 Philosopher 5 wants to drink, takes right cup

46 Philosopher 1 wants to drink, takes right cup

47 Philosopher 2 wants to drink, takes right cup

48 Philosopher 3 wants to drink, takes right cup

49 Philosopher 4 wants to drink, takes right cup

50 Deadlock!

51 they will all stay thirsty

52 this is a deadly embrace

53 this can be detected automatically 52

54 search the graph of call stacks 53

55 and look for circular dependencies 54

56 ThreadMXBean does that for us 55

57 simple deadlocks are quickly found 56

58 but what do you DO with them? 57

59 what will the dog do with the car if he ever catches it? 58

60 databases choose deadlock victim 59

61 but what does Java do? 60

62 it should probably throw an Error 61

63 but the threads simply hang up 62

64 it is best to avoid causing them! 63

65 global order of locks in program 64

66 public class LeftRightDeadlock { private final Object left = new Object(); private final Object right = new Object(); public void leftright() { synchronized (left) { synchronized (right) { dosomething(); } } } public void rightleft() { synchronized (right) { synchronized (left) { dosomethingelse(); } } } } 65

67 Interleaving causes deadlock lock left trying to lock right A leftright() BLOCKED lock right trying to lock left B rightleft() BLOCKED 66

68 we define a fixed global order 67

69 e.g. left before right 68

70 deadlock is solved! public void rightleft() { synchronized (left) { synchronized (right) { dosomethingelse(); } } } 69

71 our drinking philosophers 70

72 each cup gets a unique number 71

73 lock the highest number cup first 72

74 then lock the lower number cup 73

75 drink 74

76 unlock lower order cup 75

77 unlock higher order cup 76

78 think 77

79 Global Lock ordering We start with all the philosophers thinking

80 Philosopher 5 takes cup 5 Cup 5 has higher number 1 Remember our rule!

81 Philosopher 1 takes cup 2 Must take the cup with the higher number first 1 2 In this case cup

82 Philosopher 2 takes cup

83 Philosopher 3 takes cup

84 Philosopher 1 takes cup 1 - Drinking

85 Philosopher 1 returns Cup 1 Cups are returned in the opposite order to what they are acquired

86 Philosopher 5 takes cup 1 - Drinking

87 Philosopher 5 returns cup

88 Philosopher 1 returns cup

89 Philosopher 2 takes cup 2 - Drinking

90 Philosopher 5 returns cup

91 Philosopher 4 takes cup

92 Philosopher 2 returns cup

93 Philosopher 2 returns cup

94 Philosopher 3 takes cup 3 - Drinking

95 Philosopher 3 Returns cup

96 Philosopher 3 Returns cup

97 Philosopher 4 takes cup 4 - Drinking

98 Philosopher 4 Returns cup

99 Philosopher 4 Returns cup

100 sorting locks by property is easy 99

101 e.g. account IBAN number 100

102 or employee number 101

103 or some other characteristic 102

104 maybe even System.identityHashCode() 103

105 use "open calls" 104

106 Vector synchronizes writeobject() private synchronized void writeobject(objectoutputstream s) throws IOException { s.defaultwriteobject(); } 105

107 synchronized writeobject() is invoking s.defaultwriteobject() private synchronized void writeobject(objectoutputstream s) throws IOException { s.defaultwriteobject(); } 106

108 this is not an "open call" private synchronized void writeobject(objectoutputstream s) throws IOException { s.defaultwriteobject(); } 107

109 but can it cause problems? private synchronized void writeobject(objectoutputstream s) throws IOException { s.defaultwriteobject(); } 108

110 yes it can! private synchronized void writeobject(objectoutputstream s) throws IOException { s.defaultwriteobject(); } 109

111 serialize both vectors at same time Vector v1 = new Vector(); Vector v2 = new Vector(); v1.add(v2); v2.add(v1); 110

112 this could happen with nested data structures 111

113 it happened to an IBM client 112

114 private void writeobject(objectoutputstream stream) throws IOException { Vector<E> cloned = null; // this specially fix is for a special dead-lock in customer // program: two vectors refer each other may meet dead-lock in // synchronized serialization. Refer CMVC synchronized (this) { try { cloned = (Vector<E>) super.clone(); cloned.elementdata = elementdata.clone(); } catch (CloneNotSupportedException e) { // no deep clone, ignore the exception } } cloned.writeobjectimpl(stream); } private void writeobjectimpl(objectoutputstream stream) throws IOException { stream.defaultwriteobject(); } 113

115 Java 7 uses an "open call" private void writeobject(objectoutputstream s) throws IOException { final ObjectOutputStream.PutField fields = s.putfields(); final Object[] data; synchronized (this) { fields.put("capacityincrement", capacityincrement); fields.put("elementcount", elementcount); data = elementdata.clone(); } fields.put("elementdata", data); s.writefields(); } 114

116 More synchronized writeobject()s File StringBuffer Throwable URL Hashtable and others 115

117 we have seen the deadly embrace 116

118 are there other deadlocks? 117

119 semaphore deadlocks 118

120 Bounded DB Connection Pools For example, say you have two DB connection pools Some tasks might require connections to both databases Thus thread A might hold semaphore for D1 and wait for D2, whereas thread B might hold semaphore for D2 and be waiting for D1 119

121 public class DatabasePool { private final Semaphore connections; public DatabasePool(int connections) { this.connections = new Semaphore(connections); } public void connect() { connections.acquireuninterruptibly(); System.out.println("DatabasePool.connect"); } public void disconnect() { System.out.println("DatabasePool.disconnect"); connections.release(); } } 120

122 ThreadMXBean does not show this as a deadlock! 121

123 JVM does not detect this deadlock 122

124 JVM does not detect this deadlock 122

125 Avoiding and diagnosing deadlocks Avoiding Liveness Hazards 123

126 Avoiding and diagnosing deadlocks You cannot get a lock-ordering deadlock with a single lock Easiest way to avoid deadlocks But not always practical 124

127 Avoiding and diagnosing deadlocks For multiple locks we need to define a lock order specify and document possible lock sequences Identify where multiple locks could be acquired Do a global analysis to ensure that lock ordering is consistent This can be extremely difficult in large programs 125

128 Use open calls whenever possible 126

129 Unit Testing for lock ordering deadlocks Code typically has to be called many times before a deadlock happens How many times do you need to call it to prove that there is no deadlock? Nondeterministic unit tests are bad - they should either always pass or always fail 127

130 Testing the Bank In the transfermoney() method, a deadlock occurs if after the first lock is granted, the first thread is swapped out and another thread requests the second lock public class Bank { public boolean transfermoney(account from, Account to, Amount amount) { synchronized (from) { // if thread is swapped out here, we can end up with a deadlock synchronized (to) { return doactualtransfer(from, to, amount); } } } } 128

131 We can force the context switch 129

132 simply add a sleep after first lock 130

133 Adding a sleep to cause deadlocks public class Bank { public boolean transfermoney(account from, Account to, Amount amount) { synchronized (from) { sleepawhilefortesting(); synchronized (to) { return doactualtransfer(from, to, amount); } } } protected void sleepawhilefortesting() {} } 131

134 In our unit test we use a SlowBank public class SlowBank extends Bank { private final long timeout; private final TimeUnit unit; public SlowBank(long timeout, TimeUnit unit) { this.timeout = timeout; this.unit = unit; } protected void sleepawhilefortesting() { try { unit.sleep(timeout); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } 132

135 Won't this cause problems in production? 133

136 In production we only use Bank 134

137 HotSpot will optimize away empty sleepawhilefortesting() 135

138 it is thus a zero cost 136

139 as long as SlowBank is never used 137

140 How can you verify the lockordering deadlock? 138

141 CTRL+Break, jstack, kill -3, jconsole, etc. 139

142 but that won't be a good unit test 140

143 Better via Java's ThreadMXBean 141

144 ThreadMXBean Get instance with ManagementFactory.getThreadMXBean() findmonitordeadlockedthreads() Includes only "monitor" locks, i.e. synchronized Only way to find deadlocks in Java 5 142

145 ThreadMXBean Better is finddeadlockedthreads() Includes "monitor" and "owned" (Java 5) locks Preferred method to test for deadlocks But, does not find deadlocks between semaphores See 143

146 public class BankDeadlockTest { private final static ThreadMXBean tmb = ManagementFactory.getThreadMXBean(); private boolean isthreaddeadlocked(long tid) { long[] ids = tmb.finddeadlockedthreads(); if (ids == null) return false; for (long id : ids) { if (id == tid) return true; } return false; } 144

147 private void checkthatthreadterminates(thread thread) throws InterruptedException { for (int i = 0; i < 2000; i++) { thread.join(50); if (!thread.isalive()) return; if (isthreaddeadlocked(thread.getid())) { fail("deadlock detected!"); } } fail(thread + " did not terminate in time"); } 145

148 @Test public void testfortransferdeadlock() throws InterruptedException { final Account alpha = new Account(new Amount(1000)); final Account ubs = new Account(new Amount( )); final Bank bank = new SlowBank(100, TimeUnit.MILLISECONDS); Thread alphatoubs = new Thread("alphaToUbs") { public void run() { bank.transfermoney(alpha, ubs, new Amount(100)); } }; Thread ubstoalpha = new Thread("ubsToAlpha") { public void run() { bank.transfermoney(ubs, alpha, new Amount(100)); } }; alphatoubs.start(); ubstoalpha.start(); checkthatthreadterminates(alphatoubs); } } 146

149 Output with broken transfermoney() method We see the deadlock within about 100 milliseconds junit.framework.assertionfailederror: Deadlock detected! at BankDeadlockTest.checkThatThreadTerminates(BankDeadlockTest.java:20) at BankDeadlockTest.testForTransferDeadlock(BankDeadlockTest.java:55) 147

150 Output with broken transfermoney() method If we fix the transfermoney() method, it also completes within about 100 milliseconds This is the time that we are sleeping for testing purposes Remember that the empty sleepawhilefortesting() method will be optimized away by HotSpot 148

151 Timed lock attempts Another technique for solving deadlocks is to use the timed trylock() method of explicit Java locks 149

152 However, if trylock() fails it may be 150

153 a deadlock 151

154 or some thread taking a long time 152

155 or a thread in an infinite loop 153

156 But ThreadMXBean shows it as deadlocked 154

157 even if it is a temporary condition 155

158 The JVM has support for trylock with synchronized 156

159 but it is hidden away 157

160 So here it is 158

161 159

162 Told you it was hidden! 160

163 It is hidden for a good reason 161

164 if you need trylock functionality 162

165 rather use explicit locks (ReentrantLock) 163

166 trylock with synchronized Technically possible in Sun JVM using Unsafe.getUnsafe().tryMonitorEnter(monitor) Unsafe.getUnsafe().monitorExit(monitor) 164

167 Deadlock analysis with thread dumps 165

168 Deadlock analysis with thread dumps We can also cause a thread dump in many ways: Ctrl+Break on Windows or Ctrl-\ on Unix Invoking "kill -3" on the process id Calling jstack on the process id Only shows deadlocks since Java 6 Intrinsic locks show more information of where they were acquired 166

169 Can a deadlock be resolved? 167

170 NO with synchronized 168

171 YES with ReentrantLock 169

172 synchronized() goes into BLOCKED state 170

173 ReentrantLock.lock() goes into WAITING state 171

174 We can write a DealockArbitrator 172

175 This stops one of the threads with a DeadlockVictimError 173

176 Our special Error for deadlocks public class DeadlockVictimError extends Error { private final Thread victim; public DeadlockVictimError(Thread victim) { super("deadlock victim: " + victim); this.victim = victim; } } public Thread getvictim() { return victim; } 174

177 public class DeadlockArbitrator { private static final ThreadMXBean tmb = ManagementFactory.getThreadMXBean(); public boolean tryresolvedeadlock( int attempts, long timeout, TimeUnit unit) throws InterruptedException { for (int i = 0; i < attempts; i++) { long[] ids = tmb.finddeadlockedthreads(); if (ids == null) return true; Thread t = findthread(ids[i % ids.length]); if (t == null) throw new IllegalStateException("Could not find thread"); t.stop(new DeadlockVictimError(t)); unit.sleep(timeout); } return false; } 175

178 finding threads by id is tricky public boolean tryresolvedeadlock() throws InterruptedException { return tryresolvedeadlock(3, 1, TimeUnit.SECONDS); } } private Thread findthread(long id) { for (Thread thread : Thread.getAllStackTraces().keySet()) { if (thread.getid() == id) return thread; } return null; } 176

179 177

180 Applicability of DeadlockArbitrator Only use in extreme circumstances Code that is outside your control and that deadlocks Where you cannot prevent the deadlock Remember, it only works with ReentrantLock 178

181 Deadlock Victim Questions? by Dr Heinz Kabutz && Olivier Croisier The Java Specialists Newsletter && The Coder's Breakfast && 179

TDA - Thread Dump Analyzer

TDA - Thread Dump Analyzer TDA - Thread Dump Analyzer TDA - Thread Dump Analyzer Published September, 2008 Copyright 2006-2008 Ingo Rockel Table of Contents 1.... 1 1.1. Request Thread Dumps... 2 1.2. Thread

More information

CS11 Java. Fall 2014-2015 Lecture 7

CS11 Java. Fall 2014-2015 Lecture 7 CS11 Java Fall 2014-2015 Lecture 7 Today s Topics! All about Java Threads! Some Lab 7 tips Java Threading Recap! A program can use multiple threads to do several things at once " A thread can have local

More information

Outline of this lecture G52CON: Concepts of Concurrency

Outline of this lecture G52CON: Concepts of Concurrency Outline of this lecture G52CON: Concepts of Concurrency Lecture 10 Synchronisation in Java Natasha Alechina School of Computer Science nza@cs.nott.ac.uk mutual exclusion in Java condition synchronisation

More information

3C03 Concurrency: Condition Synchronisation

3C03 Concurrency: Condition Synchronisation 3C03 Concurrency: Condition Synchronisation Mark Handley 1 Goals n Introduce concepts of Condition synchronisation Fairness Starvation n Modelling: Relationship between guarded actions and condition synchronisation?

More information

Monitors, Java, Threads and Processes

Monitors, Java, Threads and Processes Monitors, Java, Threads and Processes 185 An object-oriented view of shared memory A semaphore can be seen as a shared object accessible through two methods: wait and signal. The idea behind the concept

More information

Monitors & Condition Synchronization

Monitors & Condition Synchronization Chapter 5 Monitors & Condition Synchronization 1 monitors & condition synchronization Concepts: monitors: encapsulated data + access procedures mutual exclusion + condition synchronization nested monitors

More information

Effective Java Programming. measurement as the basis

Effective Java Programming. measurement as the basis Effective Java Programming measurement as the basis Structure measurement as the basis benchmarking micro macro profiling why you should do this? profiling tools Motto "We should forget about small efficiencies,

More information

Java Memory Model: Content

Java Memory Model: Content Java Memory Model: Content Memory Models Double Checked Locking Problem Java Memory Model: Happens Before Relation Volatile: in depth 16 March 2012 1 Java Memory Model JMM specifies guarantees given by

More information

SSC - Concurrency and Multi-threading Java multithreading programming - Synchronisation (I)

SSC - Concurrency and Multi-threading Java multithreading programming - Synchronisation (I) SSC - Concurrency and Multi-threading Java multithreading programming - Synchronisation (I) Shan He School for Computational Science University of Birmingham Module 06-19321: SSC Outline Outline of Topics

More information

Threads 1. When writing games you need to do more than one thing at once.

Threads 1. When writing games you need to do more than one thing at once. Threads 1 Threads Slide 1 When writing games you need to do more than one thing at once. Threads offer a way of automatically allowing more than one thing to happen at the same time. Java has threads as

More information

How to Write AllSeen Alliance Self- Certification Test Cases September 25, 2014

How to Write AllSeen Alliance Self- Certification Test Cases September 25, 2014 How to Write AllSeen Alliance Self- Certification Test Cases September 25, 2014 This work is licensed under a Creative Commons Attribution 4.0 International License. http://creativecommons.org/licenses/by/4.0/

More information

Performance Improvement In Java Application

Performance Improvement In Java Application Performance Improvement In Java Application Megha Fulfagar Accenture Delivery Center for Technology in India Accenture, its logo, and High Performance Delivered are trademarks of Accenture. Agenda Performance

More information

Overview Motivating Examples Interleaving Model Semantics of Correctness Testing, Debugging, and Verification

Overview Motivating Examples Interleaving Model Semantics of Correctness Testing, Debugging, and Verification Introduction Overview Motivating Examples Interleaving Model Semantics of Correctness Testing, Debugging, and Verification Advanced Topics in Software Engineering 1 Concurrent Programs Characterized by

More information

Building a Multi-Threaded Web Server

Building a Multi-Threaded Web Server Building a Multi-Threaded Web Server In this lab we will develop a Web server in two steps. In the end, you will have built a multi-threaded Web server that is capable of processing multiple simultaneous

More information

Lecture 7: Class design for security

Lecture 7: Class design for security Lecture topics Class design for security Visibility of classes, fields, and methods Implications of using inner classes Mutability Design for sending objects across JVMs (serialization) Visibility modifiers

More information

Lecture 8: Safety and Liveness Properties

Lecture 8: Safety and Liveness Properties Concurrent Programming 19530-V (WS01) 1 Lecture 8: Safety and Liveness Properties Dr. Richard S. Hall rickhall@inf.fu-berlin.de Concurrent programming December 11, 2001 Safety Properties 2 A safety property

More information

Threads & Tasks: Executor Framework

Threads & Tasks: Executor Framework Threads & Tasks: Executor Framework Introduction & Motivation WebServer Executor Framework Callable and Future 12 April 2012 1 Threads & Tasks Motivations for using threads Actor-based Goal: Create an

More information

Unit 6: Conditions, Barriers, and RendezVous

Unit 6: Conditions, Barriers, and RendezVous SPP (Synchro et Prog Parallèle) Unit 6: Conditions, Barriers, and RendezVous François Taïani So far We have seen several synchronisation mechanisms locks (plain, re-entrant, read/write) semaphores monitors

More information

MonitorExplorer: A State Exploration-Based Approach to Testing Java Monitors

MonitorExplorer: A State Exploration-Based Approach to Testing Java Monitors Department of Computer Science and Engineering University of Texas at Arlington Arlington, TX 76019 MonitorExplorer: A State Exploration-Based Approach to Testing Java Monitors Y. Lei, R. Carver, D. Kung,

More information

Operating Systems and Networks

Operating Systems and Networks recap Operating Systems and Networks How OS manages multiple tasks Virtual memory Brief Linux demo Lecture 04: Introduction to OS-part 3 Behzad Bordbar 47 48 Contents Dual mode API to wrap system calls

More information

Fundamentals of Java Programming

Fundamentals of Java Programming Fundamentals of Java Programming This document is exclusive property of Cisco Systems, Inc. Permission is granted to print and copy this document for non-commercial distribution and exclusive use by instructors

More information

Getting Started with the Internet Communications Engine

Getting Started with the Internet Communications Engine Getting Started with the Internet Communications Engine David Vriezen April 7, 2014 Contents 1 Introduction 2 2 About Ice 2 2.1 Proxies................................. 2 3 Setting Up ICE 2 4 Slices 2

More information

Tutorial: Getting Started

Tutorial: Getting Started 9 Tutorial: Getting Started INFRASTRUCTURE A MAKEFILE PLAIN HELLO WORLD APERIODIC HELLO WORLD PERIODIC HELLO WORLD WATCH THOSE REAL-TIME PRIORITIES THEY ARE SERIOUS SUMMARY Getting started with a new platform

More information

Oracle WebLogic Server Monitoring and Performance Tuning

Oracle WebLogic Server Monitoring and Performance Tuning Oracle WebLogic Server Monitoring and Performance Tuning Duško Vukmanović Principal Sales Consultant, FMW Stuck Threads A Label given to threads not returned to thread pool after

More information

Replication on Virtual Machines

Replication on Virtual Machines Replication on Virtual Machines Siggi Cherem CS 717 November 23rd, 2004 Outline 1 Introduction The Java Virtual Machine 2 Napper, Alvisi, Vin - DSN 2003 Introduction JVM as state machine Addressing non-determinism

More information

Monitors and Exceptions : How to Implement Java efficiently. Andreas Krall and Mark Probst Technische Universitaet Wien

Monitors and Exceptions : How to Implement Java efficiently. Andreas Krall and Mark Probst Technische Universitaet Wien Monitors and Exceptions : How to Implement Java efficiently Andreas Krall and Mark Probst Technische Universitaet Wien 1 Outline Exceptions in CACAO Exception implementation techniques CACAO s implementation

More information

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Processes and Non-Preemptive Scheduling. Otto J. Anshus Processes and Non-Preemptive Scheduling Otto J. Anshus 1 Concurrency and Process Challenge: Physical reality is Concurrent Smart to do concurrent software instead of sequential? At least we want to have

More information

Sophos Mobile Control Web service guide

Sophos Mobile Control Web service guide Sophos Mobile Control Web service guide Product version: 3.5 Document date: July 2013 Contents 1 About Sophos Mobile Control... 3 2 Prerequisites... 4 3 Server-side implementation... 5 4 Client-side implementation...

More information

Chapter 6, The Operating System Machine Level

Chapter 6, The Operating System Machine Level Chapter 6, The Operating System Machine Level 6.1 Virtual Memory 6.2 Virtual I/O Instructions 6.3 Virtual Instructions For Parallel Processing 6.4 Example Operating Systems 6.5 Summary Virtual Memory General

More information

Essentials of Java Performance Tuning. Dr Heinz Kabutz Kirk Pepperdine Sun Java Champions

Essentials of Java Performance Tuning. Dr Heinz Kabutz Kirk Pepperdine Sun Java Champions Essentials of Java Performance Tuning Dr Heinz Kabutz Kirk Pepperdine Sun Java Champions Our Typical Story Customer JoGoSlo Ltd calls us in desperation > Millions of Rands invested > Users complain about

More information

Hoare-Style Monitors for Java

Hoare-Style Monitors for Java Hoare-Style Monitors for Java Theodore S Norvell Electrical and Computer Engineering Memorial University February 17, 2006 1 Hoare-Style Monitors Coordinating the interactions of two or more threads can

More information

Development Environment and Tools for Java. Brian Hughes IBM

Development Environment and Tools for Java. Brian Hughes IBM Development Environment and Tools for Java Brian Hughes IBM 1 Acknowledgements and Disclaimers Availability. References in this presentation to IBM products, programs, or services do not imply that they

More information

Monitoring and Managing a JVM

Monitoring and Managing a JVM Monitoring and Managing a JVM Erik Brakkee & Peter van den Berkmortel Overview About Axxerion Challenges and example Troubleshooting Memory management Tooling Best practices Conclusion About Axxerion Axxerion

More information

Topics. Producing Production Quality Software. Concurrent Environments. Why Use Concurrency? Models of concurrency Concurrency in Java

Topics. Producing Production Quality Software. Concurrent Environments. Why Use Concurrency? Models of concurrency Concurrency in Java Topics Producing Production Quality Software Models of concurrency Concurrency in Java Lecture 12: Concurrent and Distributed Programming Prof. Arthur P. Goldberg Fall, 2005 2 Why Use Concurrency? Concurrent

More information

! Past few lectures: Ø Locks: provide mutual exclusion Ø Condition variables: provide conditional synchronization

! Past few lectures: Ø Locks: provide mutual exclusion Ø Condition variables: provide conditional synchronization 1 Synchronization Constructs! Synchronization Ø Coordinating execution of multiple threads that share data structures Semaphores and Monitors: High-level Synchronization Constructs! Past few lectures:

More information

Programming by Contract. Programming by Contract: Motivation. Programming by Contract: Preconditions and Postconditions

Programming by Contract. Programming by Contract: Motivation. Programming by Contract: Preconditions and Postconditions COMP209 Object Oriented Programming Designing Classes 2 Mark Hall Programming by Contract (adapted from slides by Mark Utting) Preconditions Postconditions Class invariants Programming by Contract An agreement

More information

Java Coding Practices for Improved Application Performance

Java Coding Practices for Improved Application Performance 1 Java Coding Practices for Improved Application Performance Lloyd Hagemo Senior Director Application Infrastructure Management Group Candle Corporation In the beginning, Java became the language of the

More information

Chapter 7: Deadlocks!

Chapter 7: Deadlocks! The image cannot be displayed. Your computer may not have enough memory to open the image, or the image may have been corrupted. Restart your computer, and then open the file again. If the red x still

More information

Monitor-Konzepte. nach Brinch Hansen. Konzepte von Betriebssystem-Komponenten: Konkurrenz und Koordinierung in Manycore-Systemen.

Monitor-Konzepte. nach Brinch Hansen. Konzepte von Betriebssystem-Komponenten: Konkurrenz und Koordinierung in Manycore-Systemen. Konzepte von Betriebssystem-Komponenten: Konkurrenz und Koordinierung in Manycore-Systemen Monitor-Konzepte nach Brinch Hansen 18.07.2013 Krzysztof Mazur 2 Motivation Writing to a log file???? 3 Motivation

More information

1.1. Over view. 1.2. Example 1: CPU Slot Distribution A example to test the distribution of cpu slot.

1.1. Over view. 1.2. Example 1: CPU Slot Distribution A example to test the distribution of cpu slot. 1. JVM, Threads, and Monitors See also: http://java.sun.com/docs/books/vmspec/2nd-edition/html/vmspec- TOC.doc.html I have copied material from there. Thanks to Tim Lindholm Frank Yellin. 1.1. Over view

More information

Overview. CMSC 330: Organization of Programming Languages. Synchronization Example (Java 1.5) Lock Interface (Java 1.5) ReentrantLock Class (Java 1.

Overview. CMSC 330: Organization of Programming Languages. Synchronization Example (Java 1.5) Lock Interface (Java 1.5) ReentrantLock Class (Java 1. CMSC 330: Organization of Programming Languages Java 1.5, Ruby, and MapReduce Overview Java 1.5 ReentrantLock class Condition interface - await( ), signalall( ) Ruby multithreading Concurrent programming

More information

OBJECT ORIENTED PROGRAMMING LANGUAGE

OBJECT ORIENTED PROGRAMMING LANGUAGE UNIT-6 (MULTI THREADING) Multi Threading: Java Language Classes The java.lang package contains the collection of base types (language types) that are always imported into any given compilation unit. This

More information

Semaphores and Monitors: High-level Synchronization Constructs

Semaphores and Monitors: High-level Synchronization Constructs Semaphores and Monitors: High-level Synchronization Constructs 1 Synchronization Constructs Synchronization Coordinating execution of multiple threads that share data structures Past few lectures: Locks:

More information

Why Threads Are A Bad Idea (for most purposes)

Why Threads Are A Bad Idea (for most purposes) Why Threads Are A Bad Idea (for most purposes) John Ousterhout Sun Microsystems Laboratories john.ousterhout@eng.sun.com http://www.sunlabs.com/~ouster Introduction Threads: Grew up in OS world (processes).

More information

B M C S O F T W A R E, I N C. BASIC BEST PRACTICES. Ross Cochran Principal SW Consultant

B M C S O F T W A R E, I N C. BASIC BEST PRACTICES. Ross Cochran Principal SW Consultant B M C S O F T W A R E, I N C. PATROL FOR WEBSPHERE APPLICATION SERVER BASIC BEST PRACTICES Ross Cochran Principal SW Consultant PAT R O L F O R W E B S P H E R E A P P L I C AT I O N S E R V E R BEST PRACTICES

More information

No no-argument constructor. No default constructor found

No no-argument constructor. No default constructor found Every software developer deals with bugs. The really tough bugs aren t detected by the compiler. Nasty bugs manifest themselves only when executed at runtime. Here is a list of the top ten difficult and

More information

Last Class: Semaphores

Last Class: Semaphores Last Class: Semaphores A semaphore S supports two atomic operations: S Wait(): get a semaphore, wait if busy semaphore S is available. S Signal(): release the semaphore, wake up a process if one is waiting

More information

JAVA - MULTITHREADING

JAVA - MULTITHREADING JAVA - MULTITHREADING http://www.tutorialspoint.com/java/java_multithreading.htm Copyright tutorialspoint.com Java is amulti threaded programming language which means we can develop multi threaded program

More information

Concurrent Programming

Concurrent Programming Concurrent Programming Shared Memory Passing the baton Monitors Verónica Gaspes www.hh.se/staff/vero CERES, November 2, 2007 ceres Outline 1 Recap 2 Readers & Writers Readers & writers (mutual exclusion)

More information

(Pessimistic) Timestamp Ordering. Rules for read and write Operations. Pessimistic Timestamp Ordering. Write Operations and Timestamps

(Pessimistic) Timestamp Ordering. Rules for read and write Operations. Pessimistic Timestamp Ordering. Write Operations and Timestamps (Pessimistic) stamp Ordering Another approach to concurrency control: Assign a timestamp ts(t) to transaction T at the moment it starts Using Lamport's timestamps: total order is given. In distributed

More information

Chapter 8 Implementing FSP Models in Java

Chapter 8 Implementing FSP Models in Java Chapter 8 Implementing FSP Models in Java 1 8.1.1: The Carpark Model A controller is required for a carpark, which only permits cars to enter when the carpark is not full and does not permit cars to leave

More information

Real Time Programming: Concepts

Real Time Programming: Concepts Real Time Programming: Concepts Radek Pelánek Plan at first we will study basic concepts related to real time programming then we will have a look at specific programming languages and study how they realize

More information

Lecture 6: Introduction to Monitors and Semaphores

Lecture 6: Introduction to Monitors and Semaphores Concurrent Programming 19530-V (WS01) Lecture 6: Introduction to Monitors and Semaphores Dr. Richard S. Hall rickhall@inf.fu-berlin.de Concurrent programming November 27, 2001 Abstracting Locking Details

More information

How to use IBM HeapAnalyzer to diagnose Java heap issues

How to use IBM HeapAnalyzer to diagnose Java heap issues IBM Software Group How to use IBM HeapAnalyzer to diagnose Java heap issues Jinwoo Hwang (jinwoo@us.ibm.com) IBM HeapAnalyzer Architect/Developer WebSphere Support Technical Exchange Introduction Java

More information

Division of Informatics, University of Edinburgh

Division of Informatics, University of Edinburgh CS1Bh Lecture Note 20 Client/server computing A modern computing environment consists of not just one computer, but several. When designing such an arrangement of computers it might at first seem that

More information

MASSACHUSETTS INSTITUTE OF TECHNOLOGY. 6.033 Computer Systems Engineering: Spring 2013. Quiz I Solutions

MASSACHUSETTS INSTITUTE OF TECHNOLOGY. 6.033 Computer Systems Engineering: Spring 2013. Quiz I Solutions Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY 6.033 Computer Systems Engineering: Spring 2013 Quiz I Solutions There are 11 questions and 8 pages in this

More information

race conditions Image courtesy of photostock / FreeDigitalPhotos.net Flavia Rainone - Principal Software Engineer

race conditions Image courtesy of photostock / FreeDigitalPhotos.net Flavia Rainone - Principal Software Engineer Boston race conditions? Image courtesy of photostock / FreeDigitalPhotos.net 2 race conditions Race conditions arise in software when separate computer processes or threads of execution depend on some

More information

Java Troubleshooting and Performance

Java Troubleshooting and Performance Java Troubleshooting and Performance Margus Pala Java Fundamentals 08.12.2014 Agenda Debugger Thread dumps Memory dumps Crash dumps Tools/profilers Rules of (performance) optimization 1. Don't optimize

More information

Lecture 6: Semaphores and Monitors

Lecture 6: Semaphores and Monitors HW 2 Due Tuesday 10/18 Lecture 6: Semaphores and Monitors CSE 120: Principles of Operating Systems Alex C. Snoeren Higher-Level Synchronization We looked at using locks to provide mutual exclusion Locks

More information

Operating Systems for Parallel Processing Assistent Lecturer Alecu Felician Economic Informatics Department Academy of Economic Studies Bucharest

Operating Systems for Parallel Processing Assistent Lecturer Alecu Felician Economic Informatics Department Academy of Economic Studies Bucharest Operating Systems for Parallel Processing Assistent Lecturer Alecu Felician Economic Informatics Department Academy of Economic Studies Bucharest 1. Introduction Few years ago, parallel computers could

More information

Each of the advisory has a health level indicating severity of the issue found, pattern, name, keyword and related advice.

Each of the advisory has a health level indicating severity of the issue found, pattern, name, keyword and related advice. We'll do the analysis for you! Thread Dump Analysis is a key tool for performance tuning and troubleshooting of Java based applications. The current set of TDA tools (Samurai/TDA) dont mine the thread

More information

Integrated Error-Detection Techniques: Find More Bugs in Java Applications

Integrated Error-Detection Techniques: Find More Bugs in Java Applications Integrated Error-Detection Techniques: Find More Bugs in Java Applications Software verification techniques such as pattern-based static code analysis, runtime error detection, unit testing, and flow analysis

More information

UI Performance Monitoring

UI Performance Monitoring UI Performance Monitoring SWT API to Monitor UI Delays Terry Parker, Google Contents 1. 2. 3. 4. 5. 6. 7. Definition Motivation The new API Monitoring UI Delays Diagnosing UI Delays Problems Found! Next

More information

Creating a Simple, Multithreaded Chat System with Java

Creating a Simple, Multithreaded Chat System with Java Creating a Simple, Multithreaded Chat System with Java Introduction by George Crawford III In this edition of Objective Viewpoint, you will learn how to develop a simple chat system. The program will demonstrate

More information

Concurrent programming in Java

Concurrent programming in Java Concurrent programming in Java INF4140 04.10.12 Lecture 5 0 Book: Andrews - ch.05 (5.4) Book: Magee & Kramer ch.04 - ch.07 INF4140 (04.10.12) Concurrent programming in Java Lecture 5 1 / 33 Outline 1 Monitors:

More information

Managing Rack-Mount Servers

Managing Rack-Mount Servers Managing Rack-Mount Servers This chapter includes the following sections: Rack-Mount Server Management, page 1 Guidelines for Removing and Decommissioning Rack-Mount Servers, page 2 Booting Rack-Mount

More information

Optimizing Generation of Object Graphs in Java PathFinder

Optimizing Generation of Object Graphs in Java PathFinder Optimizing Generation of Object Graphs in Java PathFinder Milos Gligoric, Tihomir Gvero, Steven Lauterburg, Darko Marinov, Sarfraz Khurshid JPF Workshop 1.5.8 Bugs Six Decades Ago 1947: Harvard Mark II

More information

www.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 www.virtualians.pk

www.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 www.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 Which of the following is a general purpose container? JFrame Dialog JPanel JApplet Which of the following package needs to be import while handling

More information

Parallel Programming

Parallel Programming Parallel Programming 0024 Recitation Week 7 Spring Semester 2010 R 7 :: 1 0024 Spring 2010 Today s program Assignment 6 Review of semaphores Semaphores Semaphoren and (Java) monitors Semaphore implementation

More information

OPERATING SYSTEMS DEADLOCKS

OPERATING SYSTEMS DEADLOCKS OPERATING SYSTEMS DEADLOCKS Jerry Breecher 7: Deadlocks OPERATING SYSTEM Deadlocks What is a deadlock? What Is In This Chapter? Staying Safe: Preventing and Avoiding Deadlocks Living Dangerously: Let the

More information

Shared Address Space Computing: Programming

Shared Address Space Computing: Programming Shared Address Space Computing: Programming Alistair Rendell See Chapter 6 or Lin and Synder, Chapter 7 of Grama, Gupta, Karypis and Kumar, and Chapter 8 of Wilkinson and Allen Fork/Join Programming Model

More information

SYSTEM ecos Embedded Configurable Operating System

SYSTEM ecos Embedded Configurable Operating System BELONGS TO THE CYGNUS SOLUTIONS founded about 1989 initiative connected with an idea of free software ( commercial support for the free software ). Recently merged with RedHat. CYGNUS was also the original

More information

Java Interview Questions and Answers

Java Interview Questions and Answers 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java

More information

Built-in Concurrency Primitives in Java Programming Language. by Yourii Martiak and Mahir Atmis

Built-in Concurrency Primitives in Java Programming Language. by Yourii Martiak and Mahir Atmis Built-in Concurrency Primitives in Java Programming Language by Yourii Martiak and Mahir Atmis Overview One of the many strengths of Java is the built into the programming language support for concurrency

More information

Brekeke PBX Version 2 IVR Script Developer s Guide Brekeke Software, Inc.

Brekeke PBX Version 2 IVR Script Developer s Guide Brekeke Software, Inc. Brekeke PBX Version 2 IVR Script Developer s Guide Brekeke Software, Inc. Version Brekeke PBX Version 2 IVR Script Developer s Guide Revised: February 2010 Copyright This document is copyrighted by Brekeke

More information

4. Monitors. Monitors support data encapsulation and information hiding and are easily adapted to an object-oriented environment.

4. Monitors. Monitors support data encapsulation and information hiding and are easily adapted to an object-oriented environment. 4. Monitors Problems with semaphores: - shared variables and the semaphores that protect them are global variables - Operations on shared variables and semaphores distributed throughout program - difficult

More information

Databases and Information Systems II

Databases and Information Systems II Databases and Information Systems II Performance evaluation Profiling Performance evaluation New compression approach must be competible in terms of Compression ratio Compression time Decompression time

More information

SnapLogic Salesforce Snap Reference

SnapLogic Salesforce Snap Reference SnapLogic Salesforce Snap Reference Document Release: October 2012 SnapLogic, Inc. 71 East Third Avenue San Mateo, California 94401 U.S.A. www.snaplogic.com Copyright Information 2012 SnapLogic, Inc. All

More information

Debugging Java performance problems. Ryan Matteson matty91@gmail.com http://prefetch.net

Debugging Java performance problems. Ryan Matteson matty91@gmail.com http://prefetch.net Debugging Java performance problems Ryan Matteson matty91@gmail.com http://prefetch.net Overview Tonight I am going to discuss Java performance, and how opensource tools can be used to debug performance

More information

Port of the Java Virtual Machine Kaffe to DROPS by using L4Env

Port of the Java Virtual Machine Kaffe to DROPS by using L4Env Port of the Java Virtual Machine Kaffe to DROPS by using L4Env Alexander Böttcher ab764283@os.inf.tu-dresden.de Technische Universität Dresden Faculty of Computer Science Operating System Group July 2004

More information

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C 1 An essential part of any embedded system design Programming 2 Programming in Assembly or HLL Processor and memory-sensitive

More information

ERserver. iseries. Work management

ERserver. iseries. Work management ERserver iseries Work management ERserver iseries Work management Copyright International Business Machines Corporation 1998, 2002. All rights reserved. US Government Users Restricted Rights Use, duplication

More information

ELIXIR LOAD BALANCER 2

ELIXIR LOAD BALANCER 2 ELIXIR LOAD BALANCER 2 Overview Elixir Load Balancer for Elixir Repertoire Server 7.2.2 or greater provides software solution for load balancing of Elixir Repertoire Servers. As a pure Java based software

More information

MetroPro Remote Access OMP-0476F. Zygo Corporation Laurel Brook Road P.O. Box 448 Middlefield, Connecticut 06455

MetroPro Remote Access OMP-0476F. Zygo Corporation Laurel Brook Road P.O. Box 448 Middlefield, Connecticut 06455 MetroPro Remote Access OMP-0476F Zygo Corporation Laurel Brook Road P.O. Box 448 Middlefield, Connecticut 06455 Telephone: (860) 347-8506 E-mail: inquire@zygo.com Website: www.zygo.com ZYGO CUSTOMER SUPPORT

More information

Monitoring Lock Server Performance. Monitoring Lock Server Performance. Release 10.0

Monitoring Lock Server Performance. Monitoring Lock Server Performance. Release 10.0 Monitoring Lock Server Performance Monitoring Lock Server Performance Release 10.0 Monitoring Lock Server Performance Part Number: 10-LSPM-0 Release 10.0, September 9, 2009 The information in this document

More information

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. Scanner The Scanner class is intended to be used for input. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. For example, suppose the input

More information

Java Concurrency Framework. Sidartha Gracias

Java Concurrency Framework. Sidartha Gracias Java Concurrency Framework Sidartha Gracias Executive Summary This is a beginners introduction to the java concurrency framework Some familiarity with concurrent programs is assumed However the presentation

More information

Habanero Extreme Scale Software Research Project

Habanero Extreme Scale Software Research Project Habanero Extreme Scale Software Research Project Comp215: Java Method Dispatch Zoran Budimlić (Rice University) Always remember that you are absolutely unique. Just like everyone else. - Margaret Mead

More information

Java 2 Web Developer Certification Study Guide Natalie Levi

Java 2 Web Developer Certification Study Guide Natalie Levi SYBEX Sample Chapter Java 2 Web Developer Certification Study Guide Natalie Levi Chapter 8: Thread-Safe Servlets Copyright 2002 SYBEX Inc., 1151 Marina Village Parkway, Alameda, CA 94501. World rights

More information

Outline. Computer Science 331. Stack ADT. Definition of a Stack ADT. Stacks. Parenthesis Matching. Mike Jacobson

Outline. Computer Science 331. Stack ADT. Definition of a Stack ADT. Stacks. Parenthesis Matching. Mike Jacobson Outline Computer Science 1 Stacks Mike Jacobson Department of Computer Science University of Calgary Lecture #12 1 2 Applications Array-Based Linked List-Based 4 Additional Information Mike Jacobson (University

More information

File I/O - Chapter 10. Many Stream Classes. Text Files vs Binary Files

File I/O - Chapter 10. Many Stream Classes. Text Files vs Binary Files File I/O - Chapter 10 A Java stream is a sequence of bytes. An InputStream can read from a file the console (System.in) a network socket an array of bytes in memory a StringBuffer a pipe, which is an OutputStream

More information

The Classes P and NP

The Classes P and NP The Classes P and NP We now shift gears slightly and restrict our attention to the examination of two families of problems which are very important to computer scientists. These families constitute the

More information

Transparent Redirection of Network Sockets 1

Transparent Redirection of Network Sockets 1 Transparent Redirection of Network Sockets 1 Timothy S. Mitrovich, Kenneth M. Ford, and Niranjan Suri Institute for Human & Machine Cognition University of West Florida {tmitrovi,kford,nsuri}@ai.uwf.edu

More information

OTHER TROUBLESHOOTING METHODS

OTHER TROUBLESHOOTING METHODS 5 OTHER TROUBLESHOOTING METHODS Substitution and fault insertion Remove and conquer Circle the wagons Trapping Consultation Intuition and out-of-the-box thinking 5.1 WHY USE OTHER TROUBLESHOOTING METHODS?

More information

Computer Science 483/580 Concurrent Programming Midterm Exam February 23, 2009

Computer Science 483/580 Concurrent Programming Midterm Exam February 23, 2009 Computer Science 483/580 Concurrent Programming Midterm Exam February 23, 2009 Your name There are 6 pages to this exam printed front and back. Please make sure that you have all the pages now. The exam

More information

GTask Developing asynchronous applications for multi-core efficiency

GTask Developing asynchronous applications for multi-core efficiency GTask Developing asynchronous applications for multi-core efficiency February 2009 SCALE 7x Los Angeles Christian Hergert What Is It? GTask is a mini framework to help you write asynchronous code. Dependencies

More information

Java the UML Way: Integrating Object-Oriented Design and Programming

Java the UML Way: Integrating Object-Oriented Design and Programming Java the UML Way: Integrating Object-Oriented Design and Programming by Else Lervik and Vegard B. Havdal ISBN 0-470-84386-1 John Wiley & Sons, Ltd. Table of Contents Preface xi 1 Introduction 1 1.1 Preliminaries

More information

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming 1 2 Foreword First of all, this book isn t really for dummies. I wrote it for myself and other kids who are on the team. Everything

More information

8. Condition Objects. Prof. O. Nierstrasz. Selected material 2005 Bowbeer, Goetz, Holmes, Lea and Peierls

8. Condition Objects. Prof. O. Nierstrasz. Selected material 2005 Bowbeer, Goetz, Holmes, Lea and Peierls 8. Condition Objects Prof. O. Nierstrasz Selected material 2005 Bowbeer, Goetz, Holmes, Lea and Peierls Roadmap > Condition Objects Simple Condition Objects The Nested Monitor Problem Permits and Semaphores

More information

Digital Cable TV. User Guide

Digital Cable TV. User Guide Digital Cable TV User Guide T a b l e o f C o n T e n T s DVR and Set-Top Box Basics............... 2 Remote Playback Controls................ 4 What s on TV.......................... 6 Using the OK Button..................

More information