Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf ·...

52
Chair of Software Engineering P. Eugster Concurrent Object-Oriented Programming

Transcript of Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf ·...

Page 1: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

Chair of Software Engineering P. Eugster

Concurrent Object-Oriented Programming

Page 2: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

2

Chair of Software Engineering P. Eugster

1. SCOOP part The “object lesson” (the top-down view)High-level support for concurrencyConcurrency solution integrated with a ooprogramming language, i.e., Eiffel

2. “Classic” part The “old school” approach (the bottom-up view)Following historical evolutionProblem/solution, illustrations, e.g., Java

Two Sides of the Same Coin

Page 3: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

3

Chair of Software Engineering P. Eugster

Administrative

[email protected] / [email protected]

044 632 78 [email protected]

044 632 44 68Office RZ J3 if matter of life or death

Page 4: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

4

Chair of Software Engineering P. Eugster

Lectures Overview

Lecture 1: Introduction and Motivation for Concurrent Programming

Lecture 2: Classic Approaches to Concurrent Programming

Lecture 3: Objects and Concurrency

Lecture 4: From Concurrent to Distributed Programming

Page 5: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

5

Chair of Software Engineering P. Eugster

Lecture 1: Motivation and Introduction

Page 6: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

6

Chair of Software Engineering P. Eugster

Definition

Concurrent programming

= parallel programming on a single processor?

= is about handling I/O on a host?

Page 7: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

7

Chair of Software Engineering P. Eugster

Observations

Computers have evolvedFrom Turing machinesOver von Neumann…

TypicallyParallel architectures for efficiencyDistributed architectures for

Reliability, serviceabilityNecessity

Laptops, handhelds, mobile phone, …

Page 8: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

8

Chair of Software Engineering P. Eugster

“Single Program”

Only one physical nodeA single running program Input -> Output

Page 9: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

9

Chair of Software Engineering P. Eugster

How about I/O?

If program runs continuouslyInput, e.g., keyboard, must be handledInput/output is simultaneous, i.e., concurrent

Interruptions can be usedJumps given by interruption vector

Parts of program to run without interruptionMask interruptions

Can introduce different levels of priorities

Page 10: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

10

Chair of Software Engineering P. Eugster

“Multiple Programs”

Only one physical nodeFor the time being: a running program is called a task (also process)Tasks are totally independent from one anotherThis defines the notion of “parallelism” (but not of parallel programming)

23

1

CPU Time

CPU

1

3

2

RAM

BUSTask 1 Task 2

Task 3

Physical Node

Page 11: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

11

Chair of Software Engineering P. Eugster

Tasks Overlapping “in Time”

Tasks compete for processorPriorities can help

SchedulingDefines the allocation of processor(s) to tasks

Batch processing is simplest caseNo I/O

PreemptionThe processor can be revoked from an uncompleted taskExploit processor capacity

Page 12: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

12

Chair of Software Engineering P. Eugster

“Concurrent Programs”

CPU RAM

BUSTask 1 Task 2

Task 3

2

3

1

OS

CPU RAM

BUSTask 1 Task 2

Task 3

2

3

1

OS

But there is an operating system, typically for I/O

The operating system (kernel) occupies part of the memory

Tasks can execute OS code (through system calls or interruptions)

The OS code may modify the OS memory

Tasks can thus interfere with each other

Page 13: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

13

Chair of Software Engineering P. Eugster

Interference in Concurrency

Consider concurrent programming with preemptive scheduling, reentrant procedure increase_counter()Operations of concurrent invocations will be interleavedResult if t1 and t2 execute increase_counter()concurrently?

int counter := 0;increase_counter() {

counter := counter + 1;}

mov counter, r1add r1, 1mov r1, counter

Page 14: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

14

Chair of Software Engineering P. Eugster

Tasks Overlapping “in Space”

Resources and data shared, e.g., screenPreemption

Inconsistencies can occur if possible at any pointCritical resources must be handled with care

E.g., mutual exclusion needed in critical sections

Masking interruptions (which might trigger preemption)?

Incurs losses, e.g., I/OProhibit I/O in critical sections, yet I/O represent critical resources in first place

Page 15: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

15

Chair of Software Engineering P. Eugster

“Multi-Threaded Programs”

CPU RAM

BUSTask 1 Task 2

Task 3

2

3

1

OS

CPU RAM

BUSTask 1 Task 2

Task 3

2

3

1

OS

Several tasks (threads) created by same programPrimary objective: reduce the time needed for context-switching“Light” tasks that share variables

Page 16: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

16

Chair of Software Engineering P. Eugster

Tasks vs Threads

Discrepancies?Code? Can be same also with tasks, cf. forkData? Can be same (besides OS part), cf. shared memory

Size does matter!Context switching is expensive

Page tableFile descriptorsProcessor stateResource tables..

Page 17: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

17

Chair of Software Engineering P. Eugster

“Parallel Programs”

At any moment, tasks are running

The memory will usually provide atomic r/w operations

There can be a global clock (“tightly coupled” systems)

Different architectures (MIMD, SIMD) and memory consistency models as opposed to SISD

Different granularities (instruction, function, program)

( 1)n >n

Page 18: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

18

Chair of Software Engineering P. Eugster

Hence

Parallel computing is inherently concurrentFocus on large scientific calculations

Issues1. Identify tasks, and parallelizable parts

(programmer work)2. Schedule the tasks to minimize idle timeApproaches

Provide abstractions which make some of 1. transparent to programmer“Architectures” for increased performance, reduced data access time in response to 2.

Page 19: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

19

Chair of Software Engineering P. Eugster

Distributed Programming

Tasks can interfere through the networkTransmitted data is copied to/from the OS memoryNo global clock“Loosely coupled” systemsVery different networks can be used

Page 20: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

20

Chair of Software Engineering P. Eugster

Note

Parallel computing can be done on distributed system

“Emulate” parallel hardwareSpecial case of distributed computing with assumptions

Is distributed computing vs concurrent computing just a matter of granularity?

Cf. threads vs tasks?

Page 21: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

21

Chair of Software Engineering P. Eugster

Interference in Distribution

As long as no failures are consideredNo additional ones

But nothing is perfectFailures can occur

HostsTasks: usually unit of failure, but 1 per hostCommunication

FLP-Impossibility result [Fischer,Lynch,Patterson’85]

A failed process can not be distinguished from a very slow one

Page 22: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

22

Chair of Software Engineering P. Eugster

Concurrency: Why?

Different reasonsEfficiency

Time (load distribution)Cost (resource sharing)

ReliabilityRedundancy (fault tolerance)

ServiceabilityAvailability (multiple access)

Likely a mixture

Page 23: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

23

Chair of Software Engineering P. Eugster

But mostly: Necessity

Why computers in the first place?Make everyday (work) life easier

E.g., book flightsComputer systems used to “model” life

Explicit in workflowObject-oriented programming

E.g., plane, ticket, ..This world is concurrent!

E.g., limited number of seats on the same plane!E.g., this class!

Page 24: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

24

Chair of Software Engineering P. Eugster

Attempt of Redefinition

Concurrency: naturally given, present in:Real-time: concurrency with timing constraintsParallel: explicit, heavy computations, possibly specific hardwareDistributed: physically disparate hosts

Note: parallel can be distributedPeer-to-peer: distributed, decentralized, scalability-centricUbiquitous, pervasive: peer-to-peer, resource constraintsAd-hoc mobile: ubiquitous, devoid of fixed communication backbone

Page 25: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

25

Chair of Software Engineering P. Eugster

But be Careful…

Many PCs with dual processors

Support for sourcing out threads

Shared memory model sometimes assumed for distributed systems

Page 26: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

26

Chair of Software Engineering P. Eugster

Issues in Concurrent Programming

Computation consists ofTaskswhich use synchronization mechanisms toensure consistency of data handled concurrently by tasks

Tasks

Synchronization Consistency

Page 27: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

27

Chair of Software Engineering P. Eugster

In an Object World

Slowly try to mapTasks execute actions on behalf of objectsObjects have consistency requirements depending on their semanticsActions to be performed must be synchronized

Tasks

Actions Objects

Page 28: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

28

Chair of Software Engineering P. Eugster

Ideally

Actions are feature callsMetaphor of objects as computational entities interacting by feature calls remains

Synchronization is expressed by the way these calls are made

Might lead to restrictionsSome synchronization might be derived implicitly

Page 29: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

29

Chair of Software Engineering P. Eugster

Object-Oriented Programming

Object-based programming providesencapsulation of data (information hiding)well defined interface for operations (ADT)Identity

Class-based programming providesAn abstraction and classification mechanismCode reuse through composition and inheritance

Page 30: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

30

Chair of Software Engineering P. Eugster

They seem very different!(even dealing with orthogonal concerns)

but

Robin Milner said [Matsuoka 1993]:"I can't understand why objects [of O-O languages]

are not concurrent in the first place".

Blending O-O, and

Page 31: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

31

Chair of Software Engineering P. Eugster

Why did Robin Milner say that?

Identifying concepts:Object with task, as

both (appear to) encapsulate databoth have an autonomous behaviorboth are computational structures created at run-time

Routine invocation with message passing

Page 32: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

32

Chair of Software Engineering P. Eugster

But…

With an after-look, this comparison seems rather deceptive, and overly simplifying

Variable sharing versus encapsulation?What about inheritance and composition?What about garbage collection?What about remote interaction?What about failures?

Most of the O-O language mechanisms serve purposes that do concern neither nor

Page 33: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

33

Chair of Software Engineering P. Eugster

Illustration of Issues in Current Object-Oriented Approaches to and

Page 34: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

34

Chair of Software Engineering P. Eugster

Language Approaches to and

Possibilities [Briot et al.‘98]The integration approachThe library approachThe reflection approach

These approaches can be combined

Page 35: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

35

Chair of Software Engineering P. Eugster

The Integration Approach

Identify concepts found in the language with external ones

Introduce new (syntactic) constructs

It is the simplest approachDifficult to modify a language (compilers, etc.)

It leads to cleaner/leaner code

But it can’t address everything!No flexibility

Page 36: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

36

Chair of Software Engineering P. Eugster

The Library Approach

The most common way

Provides an API to the programmer

Wraps “native” code (e.g., OS calls)

Use through inheritance or composition

Approach of choice for middleware

Page 37: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

37

Chair of Software Engineering P. Eugster

The Reflection Approach

ReflectionEnables to alter the program “interpretation”Jumps to Meta-Level and back through Meta-Object Protocol (MOP)

Certain languages (Scheme, Smalltalk) provide such capabilityE.g., Use reflection to intercept method calls (reification)Often combined with the library approachThe code is often elegantThe execution is often inefficient

Page 38: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

38

Chair of Software Engineering P. Eugster

How about Java?

class Counter {int value := 0;

public void increase() {value := value + 1;

}}

Counter c := …;

c.inrease();

Counter c := …;

c.inrease();

Page 39: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

39

Chair of Software Engineering P. Eugster

Concurrency in Java

Possibility to create (concurrent) threads and to synchronize

Each object has an exclusive locking facility

Creation of a thread by inheriting from Thread

wait(), notify(), notifyall() are methods encapsulating native code

synchronized keyword

Page 40: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

40

Chair of Software Engineering P. Eugster

Synchronized

class Counter {int value := 0;

public synchronized void increase() {value := value + 1;

}}

Counter c := …;

c.inrease();

Counter c := …;

c.inrease();

Page 41: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

41

Chair of Software Engineering P. Eugster

Exampleclass Barrier {

int num_waiting = 1…public synchronized void join() {

if (num_waiting < 3) {num_waiting += 1; wait();

}else notifyAll();

} }

class Client extends Thread {Barrier b = …;…public void run () {

… //joining the barrierb.join ();… // all clients have joined

}}

Page 42: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

42

Chair of Software Engineering P. Eugster

Execution

Each thread has its own stack of callsObjects do not belong to threads!Which thread is awoken by a notifyAll() is not specifiedLimited to (one CPU)

Thread 1

c1.runb.join

Thread 3

Thread 2 c1 bc3c2

b.wait

c3.runb.join

b.wait

c2.run

b.notifyallb.join

b.waitb.join

b.notifyallb.join

CPU Time

Page 43: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

43

Chair of Software Engineering P. Eugster

Evaluation

What kind of approach?Library, integration, reflection?

Limitations?Thread ordering?Locking granularity?

Page 44: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

44

Chair of Software Engineering P. Eugster

What if an object is on a remote host?

Threading primitives are not enough

Example solutions relying on other libraries:Networking socketsJavaRMI, CORBA, JiniJava Message ServiceJavaSpaces…

Distribution in Java

Page 45: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

45

Chair of Software Engineering P. Eugster

JavaRMI

Provides a communication (RPC) layerCompatible with CORBA (IIOP in javax.rmi)Its interface

a stub/skeleton generator (rmic)

a naming service (object registry)

Rem

ote

Pro

cedu

re C

all

Mes

sage

Pas

sing

Page 46: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

46

Chair of Software Engineering P. Eugster

Principle

InvocationsTransformed to messages, and sent to the« other side » (marshaling) by stub

The « other side »: skeletonServer-side counterpart to the stubExtracts request arguments from message (unmarshaling) and invokes the server objectMarshals return value and sends it to theinvoker side, where stub unmarshals it andreturns the result to invoker

Page 47: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

47

Chair of Software Engineering P. Eugster

Interaction Scheme

Proxy / Stub Skeleton

Invoker Invokee

I00II….I0I

Page 48: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

48

Chair of Software Engineering P. Eugster

JavaRMI Step 1: Write an Interface

import java.rmi.*;

public interface HelloInterface extends Remote {

/* return the message of the remote object, such as "Hello, world!". exception RemoteException if the remote invocation fails. */

public String say() throws RemoteException;}

String is serializable (it can be marshaled)

Page 49: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

49

Chair of Software Engineering P. Eugster

JavaRMI Step 2: Write a Server

import java.rmi.*; import java.rmi.server.

class Hello extends UnicastRemoteObject implements HelloInterface {private String message;

public Hello (String msg) throws RemoteException {message = msg; } public String say() throws RemoteException { return message; }

}

Inherits from UnicastRemoteObject

rmic Hello will generate stub and skeleton

in main() method to register:Naming.rebind ("Hello", new Hello ("Hello, world!"));

Page 50: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

50

Chair of Software Engineering P. Eugster

JavaRMI Step 3: Write a Client

import java.rmi.*;

public static void main (String[] argv) {try {

HelloInterface hello = (HelloInterface) Naming.lookup ("//se.inf.ethz/Hello");

System.out.println (hello.say());} catch (Exception e) {

System.out.println ("HelloClient exception: " + e);}

}

Uses the lookup function of the naming service

The remote object is accessed via a proxy (a.k.a. object handle, surrogate)rmiregistry starts naming service

Page 51: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

51

Chair of Software Engineering P. Eugster

Evaluation

What kind of approach?Library, integration, reflection?

Limitations (of Proxies [Liebermann’86])?Network latency?Failures?Consistency/synchronization?

Page 52: Concurrent Object-Oriented Programmingse.inf.ethz.ch/old/teaching/ss2005/0268/lectures/Lect1.pdf · Concurrent Object-Oriented Programming. 2 Chair of Software Engineering P. Eugster

52

Chair of Software Engineering P. Eugster

Conclusions

Concurrent OO programming is not simply about deploying an OO program on several tasks

Consistency requirements guide synchronization schemeHave to think about concurrency from start

Distributed OO programming is not simply about deploying a COO program on several hosts

Remote nature of things changes semanticsHave to think about distribution from start