Docsity

Distributed Computing - Net-centric Computing - Handout | CECS 327, Study notes of Computer Science

Partial preview of the text

Download Distributed Computing - Net-centric Computing - Handout | CECS 327 and more Study notes Computer Science in PDF only on Docsity!

Chapter 1

Distributed Computing:

An Introduction (4)

Net-centric Computing

Instructor: Dr. Jeho Park

Three Types of Java Program

  • (^) Applications, applets, and servlets
    • (^) A Java application program has a main method, and

runs as an independent(standalone) process

-- may run as monolithic or as distributed program

  • (^) An applet does not have a main method, and runs

using a browser’s JVM or the appletviewer.

  • (^) A servlet does not have a main method, and runs in the

context of a web server at the request of a browser

  • (^) A Java program is compiled into bytecode, a universal

object code. When run, the bytecode is interpreted by

the Java Virtual Machine (JVM).

try?

Concurrent Processing

  • Time-sharing Processes time P P P P Timesharing of a resource Actually one process at a time

Concurrent Processing

within a process

parent process child processes A parent process may spawn child processes. a process main thread child thread 1 child thread 2 A process may spawn child threads Concurrent processing within a process

Java Threads

  • The Java Virtual Machine allows an application to have multiple threads of execution running concurrently.
  • A Java Virtual Machine starts up with a single thread. The Java Virtual Machine continues to execute threads until either of the following occurs:
  • The exit method of class Runtime has been called and the security manager has permitted the exit operation to take place.
  • All threads have terminated, either by returning from the call to the run method or by throwing an exception that propagates beyond the run method.
  • Java provides a Thread class:
    • public class Thread
    • implements Runnable

Java Threads:

Two ways to create a new thread

  • Using a subclass of the^ Thread^ class
  • Using a class that implements the^ Runnable interface

Java Threads:

Using a class that implements the Runnable interface

public class RunThreads

public static void main (String[] args)

Thread p1 = new Thread(new SomeThread2(1));

p1.start();

Thread p2 = new Thread(new SomeThread2(2));

p2.start();

Thread p3 = new Thread(new SomeThread2(3));

p3.start();

class SomeThread2 implements Runnable {

int myID;

SomeThread2(int id) {

this.myID = id;

public void run() {

int i;

for (i = 1; i < 11; i++)

System.out.println ("Thread"+myID + ": " + i);

} //end class SomeThread

Thread-safe Programming

When two threads independently access and update the same data

object, the updating needs to be synchronized. If it’s not synch., the

program may end up having race condition.

fetch value in counter and load into a register increment value in register store value in register to counter time fetch value in counter and load into a register increment value in register store value in register to counter instruction executed in concurrent process or thread 1 instruction executed in concurrent process or thread 2 This execution results in the value 2 in the counter fetch value in counter and load into a register fetch value in counter and load into a register increment value in register increment value in register store value in register to counter store value in register to counter This execution results in the value 1 in the counter

Race condition

What is IPC?

  • (^) IPC or Inter Process Communication is a capability that allows one process to communicate with another process. The processes can be running on the same computer or on different computers connected through a network.

What are the primitive

operations an IPC API provides?

  • (^) Send
  • (^) Receive -- destination and data -- source and data storage -- for connection-oriented IPC: connect and accept
  • (^) Connect
  • (^) Disconnect -- for connection-oriented IPC; connection deallocation

Blocking/Nonblocking

  • (^) Synchronous/Asynchronous Operations
    • (^) SSSR
    • (^) ASSR
    • (^) SSAR
    • (^) ASAR Process 1 Process 2 blocking receive starts blocking receive returns execution flow suspended period Asynchronous Send and Synchronous Receive nonblocking send operation

Event Diagram

Web Server Web Browser

Time

request

response

Interprocess

communication

Execution flow

Process blocked