SWEA 2018 Weekplan 13

The learning goals for Week 48 are:

Mon: Concurrency and Thread Programming Wed: Course Evaluation. Outlook to Multithreaded Servers.



Notes for this weekplan:

In looking for good resources on concurrency in Java, I actually found Jenkov's tutorial pages quite OK; so we will use them instead of a book. Note that in some of the later sections, Jenkov himself implements for instance Lock - you may skip these descriptions as Java 1.5 and later provides Lock implementations.

Time will be set aside for the course evaluation. If you do not attend the lectures, please fill it out anyway!

Lab classes are tied to the Iteration 10 mandatory exercises. In addition, have a look on the exercises below.

The slides contains several small code examples. You can find most below:

  1. ThreadDemo2
  2. CounterTest
  3. Producer/Consumer (ZIP)

Additional exercises:


The 'CounterTest' program above is not thread-safe. Make it proper thread-safe by:

  1. Use 'synchronized'
  2. Use ReentrantLock class
  3. Use the AtomicInteger class

TeleMed Concurrency Issues

The TeleMedServant is the central implementation for the server side of the TeleMed system and as such acts as a Facade pattern for a subsystem of some complexity behind it: XDS database and its current FakeObject implementation, HL7 generation using builder pattern, etc.

The current design is not thread-safe! That is, it will occasional fail in case multiple threads concurrently invokes 'processAndStore()', 'getObservationsFor()', etc., which can occur if we have a multi threaded server (as the URI Tunnel version is) that is under high load.

You are required to:

  1. Demonstrate the failure(s) by testing. That is, write a main() program that creates one TeleMedServant object, spawns 100 threads that in their run() method performs a couple of hundred processAndStore() and getObservationsFor() calls on that single TeleMed instance with a few milliseconds delay in between. Start them all, and see the failure occur now and then. (Have a look at the ProducerConsumer codebase to see its main program and model your code after that.) If no errors occur - more threads, more calls, shorter delays!
  2. Fix the concurrency issue. What class of concurrency issue is it (shared resource or producer-consumer)?

Legend: The typography bold, normal, (brackets), above indicate my perception of how important the exercises are from high to optional. However, solve the mandatory project first!.