Tommy Färnqvist, IDA, Linköping University
|
|
- Barnard Lewis
- 6 years ago
- Views:
Transcription
1 Lecture 4 Threads and Networking in Java TDDC32 Lecture notes in Design and Implementation of a Software Module in Java 23 January 2013 Tommy Färnqvist, IDA, Linköping University 4.1 Lecture Topics Contents 1 Threads Introduction Thread Programming The Life of a Thread Thread Synchronization Networking The Internet Network Programming Threads 1.1 Introduction Introduction to Threads in Java In state-of-the art software, a program can be composed of multiple independent flows of control. A flow of control is more commonly referred to as a process or thread. In most of the Java programs that you ve written (probably) there was a single flow of control. Most console-based programs begin with the first statement of the method main() and work forward to the last statement of the method main(). Flow of control is often temporarily passed to other methods through invocations, but the control returned to main() after their completion. Programs with a single control flow are known as sequential processes. 4.3 Introduction to Threads in Java (cont.) Java supports the creation of programs with concurrent flows of control. These independent flows of control are called threads. Threads run within a program and make use of that program s resources in their execution. For this reason threads are also called lightweight processes (LWP). The ability to run more than one process simultaneously is an important characteristic of a modern OS such as Linux/Unix and Windows. 4.4 Typical Multithreaded Applications Used to improve the performance of applications which require extensive I/O operations. Useful in improving the responsiveness of GUI-based applications. Used when two or more clients need to run server-based applications simultaneously
2 1.2 Thread Programming Java Classes and Threads Java has several classes that support the creation and scheduling of threads. The two basic ways of creating threads in Java are: extending the Thread class or implementing the Runnable interface. (Both are found in package java.lang. Thread actually implements Runnable.) 4.6 The Java Thread Class 4.7 Java Classes and Threads (cont.) The following two simple examples, illustrate the differences in creating threads using these two different techniques. In the example, three threads are created, one that prints the character A twenty times, one that prints the character B twenty times, and a third thread that prints the integer numbers from 1 to 20. The first program is an example of extending the Thread class. The second program is an example of using the Runnable interface. This latter technique is the more common and preferred technique. 4.8 //Class to generate threads by extending the Thread class public class TestThread { // Main method public static void main(string[] args) { // Create threads PrintChar printa = new PrintChar( a, 20); PrintChar printb = new PrintChar( b, 20); PrintNum print20 = new PrintNum(20); // Start threads print20.start(); printa.start(); printb.start(); 2
3 // The thread class for printing a specified character // a specified number of times class PrintChar extends Thread { private char chartoprint; // The character to print private int times; // The times to repeat // Construct a thread with specified character // and number of times to print the character public PrintChar(char c, int t) { chartoprint = c; times = t; 4.9 // Override the run() method to tell the system what the thread will do public void run() { for (int i = 0; i < times; i++) System.out.print(charToPrint); // The thread class for printing number from 1 to n for a given n class PrintNum extends Thread { private int lastnum; // Construct a thread for print 1, 2,... i public PrintNum(int n) { lastnum = n; // Tell the thread how to run public void run() { for (int i = 1; i <= lastnum; i++) System.out.print(" " + i); //end class TestThread 4.10 //Class to generate threads by implementing the Runnable interface public class TestRunnable { // Create threads Thread printa = new Thread(new PrintChar( a, 20)); Thread printb = new Thread(new PrintChar( b, 20)); Thread print20 = new Thread(new PrintNum(20)); public static void main(string[] args) { new TestRunnable(); public TestRunnable() { // Start threads print20.start(); printa.start(); printb.start(); // The thread class for printing a specified character // a specified number of times class PrintChar implements Runnable { private char chartoprint; // The character to print private int times; // The times to repeat // Construct a thread with specified character 3
4 // and number of times to print the character public PrintChar(char c, int t) { chartoprint = c; times = t; 4.11 // Override the run() method to tell the system what the thread will do public void run() { for (int i = 0; i < times; i++) System.out.print(charToPrint); // The thread class for printing number from 1 to n for a given n class PrintNum implements Runnable { private int lastnum; // Construct a thread for print 1, 2,... i public PrintNum(int n) { lastnum = n; // Tell the thread how to run public void run() { for (int i = 1; i <= lastnum; i++) System.out.print(" " + i); //end class TestRunnable The Life of a Thread Life Cycle of a Thread At any given point in time, a thread is said to be in one of several thread states as illustrated in the diagram below Life Cycle of a Thread (cont.) 4
5 4.14 Life Cycle of a Thread (cont.) 4.15 Life Cycle of a Thread (cont.) 5
6 4.16 Life Cycle of a Thread (cont.) 4.17 Life Cycle of a Thread (cont.) 6
7 4.18 Life Cycle of a Thread (cont.) 4.19 Summary of States In The Life Cycle of a Thread 7
8 4.20 Life Cycle of a Thread A Slightly Different View At any given point in time, a thread is said to be in one of several thread states as illustrated in the diagram below Thread Priorities Every Java thread has a priority that helps the OS determine the order in which threads are scheduled. Java priorities are in the range between MIN_PRIORITY (a constant of 1) and MAX_PRIORITY (a constant of 10). Threads with a higher priority are more important to a program and should be allocated processor time before lower-priority threads. However, thread priorities cannot guarantee the order in which threads execute. By default, every thread is given priority NORM_PRIORITY (a constant of 5). Each new thread inherits the priority of the thread that created it Thread Synchronization Related and Synchronized Threads The most complicated type of threaded application involves threads which interact with each other. These are related synchronized threads (also referred to as cooperating threads). Without synchronization when multiple threads share an object and that object is modified by one or more of the threads, indeterminate results may occur. This is known as a data race or race condition. The following example illustrates a race condition. In this example, we simulate a steam boiler and the reading of its pressure
9 // class to simulate a steam boiler to illustrate a race condition // in unsynchronized threads public class SteamBoiler1 { static int pressuregauge = 0; static final int safetylimit = 50; public static void main(string [] args) { pressure1 []psi = new pressure1[10]; for (int i = 0; i < 10; i++) { psi[i] = new pressure1(); psi[i].start(); //we now have 10 threads in execution to monitor the pressure try { for (int i = 0; i < 10; i++) psi[i].join(); //wait for the thread to finish catch (Exception e) { //do nothing System.out.println(); System.out.print("Gauge reads " + pressuregauge + ", the safe limit is " + safetylimit); if (pressuregauge > safetylimit) System.out.println("...B O O M!!!"); else System.out.println("...System OK!"); 4.24 //thread class to raise the pressure in the Boiler class pressure1 extends Thread { void RaisePressure() { if (SteamBoiler1.pressureGauge < SteamBoiler1.safetyLimit-15) { //wait briefly to simulate some calculations try {sleep(100); catch (Exception e) { SteamBoiler1.pressureGauge += 15; //raise the pressure 15 psi System.out.println("Thread " + this.getname() + " finds pressure within limits - increases pressure"); else System.out.println("Thread" + this.getname() + " finds pressure too high - do nothing"); public void run() { RaisePressure(); //this thread is to raise the pressure 4.25 Thread Synchronization To prevent a race condition, access to the shared object must be properly synchronized. Lost update problem: one thread is in the process of updating the shared value and another thread also attempts to update the value. Even worse is when only part of the object is updated by each thread in which case part of the object reflects information from one thread while another part of the same object reflects information from another thread. The problem can be solved by giving one thread at a time exclusive access to code that manipulates the shared object. During that time, other threads desiring to manipulate the object must be forced to wait
10 Thread Synchronization (cont.) When the thread with exclusive access to the object finishes manipulating the object, one of the blocked threads will be allowed to proceed and access the shared object. The next selected thread will be based on some protocol. The most common of these is simply FCFS (priority-queue based). In this fashion, each thread accessing the shared object excludes all other threads from accessing the object simultaneously. This is the process known as mutual exclusion. Mutual exclusion allows the programmer to perform thread synchronization, which coordinates access to shared objects by concurrent threads Synchronization Techniques There have been many different methods used to synchronize concurrent processes. Some of the more common ones are: Test and Set Instructions. All general purpose processors now have this kind of instruction, and it is used to build higher-level synchronization constructs. Test and set does not block, that must be built on top of it. p and v semaphores. Introduced by Dijkstra in the 1960 s and was the main synchronization primitive for a long time. Its easy to build semaphores from test and set instructions. Semaphores are low-level and can be hard for programmers to read and debug. The p is short for the Dutch words proberen te verlangen which means to try to decrement and the v stands for verhogen which means to increment Synchronization Techniques (cont.) Read/write Locks. These are also commonly referred to as mutexes (although some people still use the term mutex to refer to a semaphore.) A lock provides a simple turnstile : only one thread at a time can be going through (executing in) a block protected by a lock. Again, it is easy to build a lock from semaphores. Monitors. A monitor is a higher-level synchronization construct built out of a lock plus a variable that keeps track of some related condition, such as the number of unconsumed bytes in the buffer. It is easy to build monitors from read/write locks. A monitor defines several methods as a part of its protocol. Two of those predefined methods are wait() and notify() Types of Synchronization There are two basic types of synchronization between threads: Mutual exclusion is used to protect certain critical sections of code from being executed simultaneously by two or more threads. (Synchronization without cooperation.) Signal-wait is used when one thread need to wait until another thread has completed some action before continuing. (Synchronization with cooperation.) Java includes mechanisms for both types of synchronization. All synchronization in Java is built around locks. Every Java object has an associated lock. Using appropriate syntax, you can specify that the lock for an object be locked when a method is invoked. Any further attempts to call a method for the locked object by other threads cause those threads to be blocked until the lock is unlocked Thread States With Synchronization 10
11 4.31 Deadlock Deadlock will occur when a waiting thread (call it thread 1) cannot proceed because it is waiting (either directly or indirectly) for another thread (call it thread 2) to proceed, while simultaneously thread 2 cannot proceed because it is waiting (either directly or indirectly) for thread 1 to proceed Producer/Consumer Problem Threads Without Synchronization In a producer/consumer relationship, the producer portion of an application generates data and stores it in a shared object, and the consumer portion of an application reads data from the shared object. Common examples are print spooling, copying data onto CDs, etc. In a multithreaded producer/consumer relationship, a producer thread generates data and places it in a shared object called a buffer. A consumer thread reads data from the buffer. In lab 2, you will consider how logic errors can arise if we do not synchronize access among multiple threads manipulating shared data in this scenario Monitors and Monitor Locks The way you will perform synchronization (in lab 2) is to use Java s built-in monitors. Every object has a monitor. Strictly speaking, the monitor is not allocated unless it is used. A monitor allows one thread at a time to execute inside a synchronized statement on the object. This is accomplished by acquiring a lock on the object when the program enters the synchronized statement. synchronized(object) { statements // end synchronized statements Where object is the object whose monitor lock will be acquired. If there are several synchronized statements attempting to execute on an object at the same time, only one of them may be active on the object at once all the other threads attempting to enter a synchronized statement on the same object are placed into the blocked state Mutual Exclusion Over a Block of Statements When a synchronized statement finishes executing, the monitor lock on the object is released and the highest priority blocked thread attempting to enter a synchronized statement proceeds. Applying mutual exclusion to a block of statements rather than to an entire class or an entire method is handled in much the same manner, by attaching the keyword synchronized before a block of code. You must explicitly mention in parentheses the object whose lock must be acquired before the block can be entered. The next page illustrates the steam boiler pressure gauge problem using a synchronized statement block to control the threads access to the pressure gauge
12 //thread class to raise the pressure in the Boiler class syncpressure extends Thread { static Object O = new Object(); void RaisePressure() { synchronized(o) { if (syncsteamboiler.pressuregauge < syncsteamboiler.safetylimit-15) { //wait briefly to simulate some calculations try {sleep(100); catch (Exception e) { syncsteamboiler.pressuregauge += 15; //raise the pressure 15 psi System.out.println("Thread " + this.getname() + " finds pressure within limits - increases pressure"); else System.out.println("Thread" + this.getname() + " finds pressure too high - do nothing"); public void run() { RaisePressure(); //this thread is to raise the pressure 4.36 Monitors and Monitor Locks (cont.) Java also allows synchronized methods. A synchronized method is equivalent to a synchronized statement enclosing the entire body of a method. If a thread obtains the monitor lock on an object and then discovers that it cannot continue with its task until some condition is satisfied, the thread can invoke Object method wait, releasing the monitor lock on the object. This will place the thread in the wait state. When a thread executing a synchronized statement completes or satisfies the condition on which another thread may be waiting, it can invoke Object method notify to allow a waiting thread to transition to the blocked state again. Caution: As with any multi-threaded application, care must be taken when using synchronization to achieve the desired effect and not introduce some serious defect in the application Networking 2.1 The Internet Technical Principles of the Internet Communications systems such as the Internet are best described using layered models because of their complexity. Every layer within the model has a certain task, and all layers together produce a particular communication service for the user. The layers are arranged in hierarchical form. Layers lower in the hierarchy produce a service used by the higher layers. The uppermost layer finally combines all lower layer services and constitutes the interface for applications. For the Internet, the so-called Internet reference model is used and is shown on the next slide Internet Reference Model 12
13 4.39 Internet Reference Model (cont.) The Link Layer describes the possible sub-networks of the Internet and their medium access protocols. These are, for example, Ethernets, token rings, FDDI, or ISDN networks. To its upper layer, the link layer offers communication between two computers in the same sub-network as a service. The Network Layer unites all the sub-networks to become the Internet. The service offered involves making communication possible between any two computers on the Internet. The network layer accesses the services of the link layer, in that a connection between two computers in different networks is put together for many small connections in the same network. Internet Reference Model (cont.) The Transport Layer oversees the connection of two (or more) processes between computers communicating with each other via the network layer. The Application Layer makes application-specific services available for inter-process communication. These standardized services include , file transfer and the World Wide Web. Within the layers, protocols are used for the production of a service. Protocols are instances which can be implemented either in hardware or software, and communicate with their partner instances in the same levels, but on other computers. It is only this cooperation that enables the service to be produced for the next level up. Internet Reference Model (cont.) The TCP/IP Protocol constitutes the core of Internet communication technology in the transport and network layers. Every computer on the Internet always has an implementation of both protocols, TCP (Transmission Control Protocol) and IP (Internet Protocol). The task of IP is to transfer data from one Internet computer (the sender) to another (the receiver). On this basis, TCP then organizes the communication between the two processes on these two computers Network Programming Networking Java s fundamental networking capabilities are declared by classes and interfaces of the java.net package, through which Java offers stream-based communications. The classes and interfaces of java.net also offer packet-based communications for transmitting individual packets of information. This is most commonly used to transmit audio and video over the Internet. We will focus on both sides of the client-server relationship. The client requests that some action be performed, and the server performs the action and responds to the client
14 java.net High-level APIs Implement commonly used protocols such as HTML, FTP, etc. Low-level APIs Socket-based communications Applications view networking as streams of data Connection-based protocol Uses TCP (Transmission Control Protocol) Packet-based communications Individual packets transmitted Connectionless service Uses UDP (User Datagram Protocol) 4.44 Sockets Java s socket-based communications enable applications to view networking as if it were file I/O. In other words, a program can read from a socket or write to a socket as simply as reading from a file or writing to a file. A socket is simply a software construct that represents one endpoint of a connection. Stream sockets enable a process to establish a connection with another process. While the connection is in place, data flows between the processes in continuous streams. Stream sockets provide a connection-oriented service. The protocol used for transmission is the popular TCP (Transmission Control Protocol). Provides reliable, in-order byte-stream service Sockets (cont.) Datagram sockets transmit individual packets of information. This is typically not appropriate for use by everyday programmers because the transmission protocol is UDP (User Datagram Protocol). UDP provides a connectionless service. A connectionless service does not guarantee that packets arrive at the destination in any particular order. With UDP, packets can be lost or duplicated. Significant extra programming is required on the programmer s part to deal with these problems. UDP is most appropriate for network applications that do not require the error checking and reliability of TCP Sockets (cont.) Under UDP there is no connection between the server and the client. There is no handshaking. The sender explicitly attaches the IP address and port of the destination to each packet. The server must extract the IP address and port of the sender from the received packet. From an application viewpoint, UDP provides unreliable transfer of groups of bytes ( datagrams ) between client and server Socket Programming with TCP Server process must first be running (must have created a socket). Recall that TCP is not connectionless. Client contacts the server by creating client-local socket specifying IP address and port number of server process. Client TCP establishes connection to server TCP. When contacted by client, server TCP creates a new socket for server process to communicate with client. Allows server to talk with multiple clients Source port numbers used to distinguish clients From application viewpoint: TCP provides reliable, in-order transfer of bytes ( pipe ) between client and server
15 Establishing a Simple Server Using Stream Sockets Five steps to create a simple stream server in Java: 1. ServerSocket object. Registers an available port and a maximum number of clients. 2. Each client connection handled with a Socket object. Server blocks until client connects. 3. Sending and receiving data OutputStream to send and InputStream to receive data. Methods getinputstream and getoutputstream on Socket object. 4. Process phase. Server and client communicate via streams. 5. Close streams and connections Establishing a Simple Client Using Stream Sockets Four steps to create a simple stream client in Java: 1. Create a Socket object for the client. 2. Obtains Socket s InputStream and OutputStream. 3. Process information communicated. 4. Close streams and Socket Example: client/server socket interaction via TCP 4.51 Example: Java server using TCP import java.io.*; import java.net.*; class TCPServer { public static void main(string args[]) throws Exception { String clientsentence; String capitalizedsentence; // create welcoming socket at port 6789 ServerSocket welcomesocket = new ServerSocket(6789); while (true) { // block on welcoming socket for contact by a client Socket connectionsocket = welcomesocket.accept(); // create input stream attached to socket BufferedReader infromclient = new BufferedReader( 15
16 new InputStreamReader(connectionSocket.getInputStream())); // create output stream attached to socket DataOutputStream outtoclient = new DataOutputStream( connectionsocket.getoutputstream()); 4.52 Example: Java server using TCP (cont.) // read in line from the socket clientsentence = infromclient.readline(); // process capitalizedsentence = clientsentence.touppercase() + \n ; // write out line to socket outtoclient.writebytes(capitalizedsentence); 4.53 Example: Java client using TCP //simple client application using TCP import java.io.*; import java.net.*; class TCPClient { public static void main(string args[]) throws Exception { String sentence; String modifiedsentence; // create input stream BufferedReader infromuser = new BufferedReader( new InputStreamReader(System.in)); // create client socket and connect to server Socket clientsocket = new Socket("remote-und.ida.liu.se", 6789); // create output stream attached to socket DataOutputStream outtoserver = new DataOutputStream( clientsocket.getoutputstream()); // create input stream attached to socket BufferedReader infromserver = new BufferedReader( new InputStreamReader(clientSocket.getInputStream())); 4.54 Example: Java client using TCP (cont.) sentence = infromuser.readline(); // send line to server outtoserver.writebytes(sentence + \n ); // read line from server modifiedsentence = infromserver.readline(); System.out.println("[From server:] " + modifiedsentence); clientsocket.close();
17 Voluntary Homework Problem Build a skip list for the elements 1, 3, 5, 7, 2, 4, 6, 8, inserted in that order. The results of the coin tosses are (H=head, T=tail) H, H, T, T, over and over again
Communication in Distributed Systems: Sockets Programming. Operating Systems
Communication in Distributed Systems: Sockets Programming Operating Systems TCP/IP layers Layers Message Application Transport Internet Network interface Messages (UDP) or Streams (TCP) UDP or TCP packets
More informationCSCD 330 Network Programming Spring 2018
CSCD 330 Network Programming Spring 2018 Lecture 6 Application Layer Socket Programming in Java Reading for Java Client/Server see Relevant Links Some Material in these slides from J.F Kurose and K.W.
More informationCS 355. Computer Networking. Wei Lu, Ph.D., P.Eng.
CS 355 Computer Networking Wei Lu, Ph.D., P.Eng. Chapter 2: Application Layer Overview: Principles of network applications? Introduction to Wireshark Web and HTTP FTP Electronic Mail: SMTP, POP3, IMAP
More informationChapter 2 Application Layer
Chapter 2 Application Layer A note on the use of these ppt slides: We re making these slides freely available to all (faculty, students, readers). They re in PowerPoint form so you can add, modify, and
More informationChapter 2: outline. 2.1 principles of network applications. 2.6 P2P applications 2.7 socket programming with UDP and TCP
Chapter 2: outline 2.1 principles of network applications app architectures app requirements 2.2 Web and HTTP 2.3 FTP 2.4 electronic mail SMTP, POP3, IMAP 2.5 DNS 2.6 P2P applications 2.7 socket programming
More informationIntroduction to Sockets 9/25/14
Introduction to Sockets 9/25/14 81 Remote communication Inter-process communication is at the heart of all distributed systems Using the network protocol stack on a node is the only way to communicate
More informationChapter 2 outline. 2.1 Principles of app layer protocols
Chapter 2 outline 2.1 Principles of app layer protocols clients and servers app requirements 2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail SMTP, POP3, IMAP 2.5 DNS 2.6 Socket programming with TCP 2.7 Socket
More informationClient/Server Computing & Socket Programming
CPSC 852 Intering Client/Server Computing & Socket Programming Michele Weigle Department of Computer Science Clemson University mweigle@cs.clemson.edu http://www.cs.clemson.edu/~mweigle/courses/cpsc852
More informationChapter 2 Application Layer
Internet and Intranet Protocols and Applications Lecture 4: Application Layer 3: Socket Programming Spring 2006 Arthur Goldberg Computer Science Department New York University artg@cs.nyu.edu Chapter 2
More informationLayer 4 - Transport Layer. What do we need a Transport Layer for? Transport Protocols in the TCP/IP Reference Model. The Transport Layer TCP and UDP
Layer 4 - Transport Layer Core of the protocol hierarchy: Network-independent, reliable and economical data transfer Tasks of the transport layer: Connection-oriented or connectionless data transfer Addressing
More informationLayer 4 - Transport Layer
Layer 4 - Transport Layer Core of the protocol hierarchy: Network-independent, reliable and economical data transfer Tasks of the transport layer: Connection-oriented or connectionless data transfer Addressing
More informationLecture 3. Java Socket Programming. TCP, UDP and URL
Lecture 3 TCP, UDP and URL 1 Java Sockets Programming The package java.net provides support for sockets programming (and more). Typically you import everything defined in this package with: import java.net.*;
More informationComputer Networking Introduction
Computer Networking Introduction Halgurd S. Maghdid Software Engineering Department Koya University-Koya, Kurdistan-Iraq Lecture No.6 Chapter 2: outline 2.1 principles of network applications app architectures
More informationMultithread Computing
Multithread Computing About This Lecture Purpose To learn multithread programming in Java What You Will Learn ¾ Benefits of multithreading ¾ Class Thread and interface Runnable ¾ Thread methods and thread
More informationJAVA SOCKET PROGRAMMING
JAVA SOCKET PROGRAMMING WHAT IS A SOCKET? Socket The combination of an IP address and a port number. (RFC 793 original TCP specification) The name of the Berkeley-derived application programming interfaces
More informationCSCD 330 Network Programming Spring 2018
CSCD 330 Network Programming Spring 2018 Lecture 7 Application Layer Socket Programming in Java Reading: Chapter 2, Java links Relevant Links page Some Material in these slides from J.F Kurose and K.W.
More informationCSCD 330 Network Programming Winter 2019
CSCD 330 Network Programming Winter 2019 Lecture 7 Application Layer Socket Programming in Java Reading: Chapter 2, Java links Relevant Links page Some Material in these slides from J.F Kurose and K.W.
More informationCPSC 441 UDP Socket Programming. Department of Computer Science University of Calgary
CPSC 441 UDP Socket Programming Department of Computer Science University of Calgary Socket programming using UDP (vs TCP) UDP: no connection between client and server vno handshaking vsender explicitly
More informationLecture 05: Application Layer (Part 02) FTP, Peer-to-Peer, . Dr. Anis Koubaa
NET 331 Computer Networks Lecture 05: Application Layer (Part 02) FTP, Peer-to-Peer, Email Dr. Anis Koubaa Reformatted slides from textbook Computer Networking a top-down appraoch, Fifth Edition by Kurose
More informationComputer Networks Unit II Transport layer (2012 pattern)
Computer Networks Unit II Transport layer (2012 pattern) By Prof. B.A.Khivsara Assistant Prof. Department of Computer Engg. SNJB s KBJ COE, Chandwad Introduction 1-1 Chapter 2: ROAD MAP Transport Layer
More informationProcess Communication COMPUTER NETWORKING Part 2
Process Communication COMPUTER NETWORKING Part 2 Client-server paradigm and Socket Programming ch 18 Thanks to the authors of the textbook [USP] and [KR] for providing the base slides. I made several changes/additions.
More informationComputer Networks. 5th of February, This exam consists of 6 questions with subquestions. Every subquestion counts for 10 points.
Computer Networks 5th of February, 05 This exam consists of 6 questions with subquestions. Every subquestion counts for 0 points. Mark every page with name and student number. Use of books, additional
More informationLecture 10 Multithreading
Lecture 10 Multithreading Introduction to Threads Threads in Java public class TaskThreadDemo public static void main(string[] args) // Create tasks Runnable printa = new PrintChar('a', 100); Runnable
More informationNetworking: IPv6, UDP and TCP. Network Programming in Java UDP and TCP
Networking: IPv6, UDP and TCP Network Programming in Java UDP and TCP SCOMRED, November 2018 Instituto Superior de Engenharia do Porto (ISEP) Departamento de Engenharia Informática(DEI) SWitCH Computing
More informationCPSC 441 Tutorial - 11 UDP Socket Programming Department of Computer Science University of Calgary
CPSC 441 Tutorial - 11 UDP Programming Department of Computer Science University of Calgary TCP Vs UDP Input: receives packet (TCP receives byte stream ) Output: sends packet (TCP sends byte stream ) What
More informationComputer Communication Networks Socket Programming
Computer Communication Networks Socket Programming ICEN/ICSI 416 Fall 2018 Prof. Aveek Dutta 1 Application Programming Interface Interface exported by the network Since most network protocols are implemented
More informationSRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR
SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR 603203 DEPARTMENT OF COMPUTER SCIENCE & APPLICATIONS QUESTION BANK (2017-2018) Course / Branch : M.Sc.,CST Semester / Year : EVEN / III Subject Name
More informationComputer Networks. 2.Application Layer. László Böszörményi Computer Networks Application Layer - 1
Computer Networks 2.Application Layer László Böszörményi Computer Networks Application Layer - 1 Applications + App Layer Protocols Applications, app. processes E.g., E-mail, WWW, DNS, P2P file sharing,
More informationLecture 3: Socket Programming
Lecture 3: Socket Programming Prof. Shervin Shirmohammadi SITE, University of Ottawa Fall 2005 CEG4183/ELG4183 3-1 Sockets From a logical perspective, a Socket is a communication end point. It is not a
More informationJAVA and J2EE UNIT - 4 Multithreaded Programming And Event Handling
JAVA and J2EE UNIT - 4 Multithreaded Programming And Event Handling Multithreaded Programming Topics Multi Threaded Programming What are threads? How to make the classes threadable; Extending threads;
More informationJava Support for developing TCP Network Based Programs
Java Support for developing TCP Network Based Programs 1 How to Write a Network Based Program (In Java) As mentioned, we will use the TCP Transport Protocol. To communicate over TCP, a client program and
More informationJava Network Programming
CPSC 360 Network Programming Java Network Programming Michele Weigle Department of Computer Science Clemson University mweigle@cs.clemson.edu January 24, 2005 http://www.cs.clemson.edu/~mweigle/courses/cpsc360
More informationThreads & Timers. CSE260, Computer Science B: Honors Stony Brook University
Threads & Timers CSE260, Computer Science B: Honors Stony Brook University http://www.cs.stonybrook.edu/~cse260 Multi-tasking When you re working, how many different applications do you have open at one
More informationCS September 2017
Machine vs. transport endpoints IP is a network layer protocol: packets address only the machine IP header identifies source IP address, destination IP address Distributed Systems 01r. Sockets Programming
More informationMultithreaded Programming Part II. CSE 219 Stony Brook University, Department of Computer Science
Multithreaded Programming Part II CSE 219 Stony Brook University, Thread Scheduling In a Java application, main is a thread on its own Once multiple threads are made Runnable the thread scheduler of the
More informationCSCD 330 Network Programming
CSCD 330 Network Programming Lecture 8 Client-Server Programming Threads Spring 2017 Reading: Chapter 2, Relevant Links - Threads Some Material in these slides from J.F Kurose and K.W. Ross All material
More informationJava Socket Application. Distributed Systems IT332
Java Socket Application Distributed Systems IT332 Outline Socket Communication Socket packages in Java Multithreaded Server Socket Communication A distributed system based on the client server model consists
More informationCSCD 330 Network Programming
CSCD 330 Network Programming Lecture 8 Client-Server Programming Threads Spring 2018 Reading: Chapter 2, Relevant Links - Threads Some Material in these slides from J.F Kurose and K.W. Ross All material
More informationDistributed Systems Recitation 2. Tamim Jabban
15-440 Distributed Systems Recitation 2 Tamim Jabban Agenda Communication via Sockets in Java (this enables you to complete PS1 and start P1 (goes out today!)) Multi-threading in Java Coding a full Client-Server
More informationConcurrent Programming using Threads
Concurrent Programming using Threads Threads are a control mechanism that enable you to write concurrent programs. You can think of a thread in an object-oriented language as a special kind of system object
More informationInternet Technology 2/7/2013
Sample Client-Server Program Internet Technology 02r. Programming with Sockets Paul Krzyzanowski Rutgers University Spring 2013 To illustrate programming with TCP/IP sockets, we ll write a small client-server
More informationChapter 4: Processes
Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication in Client-Server Systems 4.1 Process Concept An operating
More informationMulti-threaded Web Server (Assignment 1) Georgios Georgiadis
Multi-threaded Web Server (Assignment 1) Georgios Georgiadis Overview Multi-threaded Web Server What to do and how to do it HTTP messages Processes and threads ComputerComm '09 2 Multi-threaded Web Server
More informationIntroduction to Java Threads
Object-Oriented Programming Introduction to Java Threads RIT CS 1 "Concurrent" Execution Here s what could happen when you run this Java program and launch 3 instances on a single CPU architecture. The
More informationApplication Layer. Application Layer 1. By Mikkel Christiansen for NA mm7 Spring 2004
Application Layer By Mikkel Christiansen for NA mm7 Spring 2004 Based on power-point material from J.F Kurose and K.W. Ross website Application Layer 1 Last on NA End-systems PCs workstations, servers
More informationThreads and Parallelism in Java
Threads and Parallelism in Java Java is one of the few main stream programming languages to explicitly provide for user-programmed parallelism in the form of threads. A Java programmer may organize a program
More informationWe will cover in this order: 2.1, 2.7, 2.5, 2.4, 2.2
CSE 422 Notes, Set 2 These slides contain materials provided with the text: Computer Networking: A Top Down Approach,5 th edition, by Jim Kurose and Keith Ross, Addison-Wesley, April 2009. Additional figures
More informationPerformance Throughput Utilization of system resources
Concurrency 1. Why concurrent programming?... 2 2. Evolution... 2 3. Definitions... 3 4. Concurrent languages... 5 5. Problems with concurrency... 6 6. Process Interactions... 7 7. Low-level Concurrency
More informationCSCD 330 Network Programming
CSCD 330 Network Programming Lecture 8 Client-Server Programming Threads Winter 2015 Reading: Chapter 2, Relevant Links Some Material in these slides from J.F Kurose and K.W. Ross All material copyright
More informationAST: scalable synchronization Supervisors guide 2002
AST: scalable synchronization Supervisors guide 00 tim.harris@cl.cam.ac.uk These are some notes about the topics that I intended the questions to draw on. Do let me know if you find the questions unclear
More informationReading from URL. Intent - open URL get an input stream on the connection, and read from the input stream.
Simple Networking Loading applets from the network. Applets are referenced in a HTML file. Java programs can use URLs to connect to and retrieve information over the network. Uniform Resource Locator (URL)
More informationApplication Programming Interfaces
Application Programming Interfaces The TCP/IP protocol suite provides only the protocols that can be used by processes to communicate across a network. Though standarized, how these protocols are implemented
More informationPart I: Communication and Networking
Review what we learned Part I: Communication and Networking Communication and Networking: Week 5-6, Lectures 2-7 Lecture 1 OSI vs TCP/IP model OSI model Protocols TCP/IP model Application FTP SMTP HTTP
More informationMultithreaded Programming
Multithreaded Programming Multithreaded programming basics Concurrency is the ability to run multiple parts of the program in parallel. In Concurrent programming, there are two units of execution: Processes
More informationAdvanced Java Programming. Networking
Advanced Java Programming Networking Eran Werner and Ohad Barzilay Tel-Aviv University Advanced Java Programming, Spring 2006 1 Overview of networking Advanced Java Programming, Spring 2006 2 TCP/IP protocol
More informationThe University of Texas at Arlington
The University of Texas at Arlington Lecture 10: Threading and Parallel Programming Constraints CSE 5343/4342 Embedded d Systems II Objectives: Lab 3: Windows Threads (win32 threading API) Convert serial
More informationConcurrent Programming
Concurrency Concurrent Programming A sequential program has a single thread of control. Its execution is called a process. A concurrent program has multiple threads of control. They may be executed as
More informationOBJECT ORIENTED PROGRAMMING
1 OBJECT ORIENTED PROGRAMMING Lecture 14 Networking Basics Outline 2 Networking Basics Socket IP Address DNS Client/Server Networking Class & Interface URL Demonstrating URL Networking 3 Java is practically
More informationChapter II: Application Layer
Chapter II: Application Layer UG3 Computer Communications & Networks (COMN) Myungjin Lee myungjin.lee@ed.ac.uk Slides copyright of Kurose and Ross Internet hourglass Here 2 Some network apps e-mail web
More informationCS 556 Distributed Systems
CS 556 Distributed Systems Tutorial on 4 Oct 2002 Threads A thread is a lightweight process a single sequential flow of execution within a program Threads make possible the implementation of programs that
More informationBy: Abhishek Khare (SVIM - INDORE M.P)
By: Abhishek Khare (SVIM - INDORE M.P) MCA 405 Elective I (A) Java Programming & Technology UNIT-2 Interface,Multithreading,Exception Handling Interfaces : defining an interface, implementing & applying
More informationJava for Interfaces and Networks
Java for Interfaces and Networks Threads and Networking Federico Pecora School of Science and Technology Örebro University federico.pecora@oru.se Federico Pecora Java for Interfaces and Networks Lecture
More informationUser Space Multithreading. Computer Science, University of Warwick
User Space Multithreading 1 Threads Thread short for thread of execution/control B efore create Global During create Global Data Data Executing Code Code Stack Stack Stack A fter create Global Data Executing
More informationDiscussion CSE 224. Week 4
Discussion CSE 224 Week 4 Midterm The midterm will cover - 1. Topics discussed in lecture 2. Research papers from the homeworks 3. Textbook readings from Unit 1 and Unit 2 HW 3&4 Clarifications 1. The
More informationTCP and Concurrency. The third assignment at DA
TCP and Concurrency The third assignment at DA2402 2009-03-05 Jonas Lundberg/Ola Flygt adapted to Java by Marcus Edvinsson maintained by Marcus Edvinsson Matematiska och systemtekniska institutionen, MSI
More informationMultiple Inheritance. Computer object can be viewed as
Multiple Inheritance We have seen that a class may be derived from a given parent class. It is sometimes useful to allow a class to be derived from more than one parent, inheriting members of all parents.
More informationCSCE 463/612 Networks and Distributed Processing Spring 2018
CSCE 463/612 Networks and Distributed Processing Spring 2018 Introduction Dmitri Loguinov Texas A&M University January 23, 2018 Original slides copyright 1996-2004 J.F Kurose and K.W. Ross 1 Updates Recv
More informationInfo 408 Distributed Applications programming 2 nd semester of 2017/2018 Credits: 5 Lecturer: Dr. Antoun Yaacoub
Lebanese University Faculty of Science I Master 1 degree Computer Science Info 408 Distributed Applications programming 2 nd semester of 2017/2018 Credits: 5 Lecturer: Dr. Antoun Yaacoub Starting Network
More informationJava Networking (sockets)
Java Networking (sockets) Rui Moreira Links: http://java.sun.com/docs/books/tutorial/networking/toc.html#sockets http://www.javaworld.com/javaworld/jw-12-1996/jw-12-sockets_p.html Networking Computers
More informationMultitasking Multitasking allows several activities to occur concurrently on the computer. A distinction is usually made between: Process-based multit
Threads Multitasking Multitasking allows several activities to occur concurrently on the computer. A distinction is usually made between: Process-based multitasking Thread-based multitasking Multitasking
More informationCommunication Paradigms
Communication Paradigms Nicola Dragoni Embedded Systems Engineering DTU Compute 1. Interprocess Communication Direct Communication: Sockets Indirect Communication: IP Multicast 2. High Level Communication
More informationNetworking and Security
Chapter 03 Networking and Security Mr. Nilesh Vishwasrao Patil Government Polytechnic Ahmednagar Socket Network socket is an endpoint of an interprocess communication flow across a computer network. Sockets
More informationJava s Implementation of Concurrency, and how to use it in our applications.
Java s Implementation of Concurrency, and how to use it in our applications. 1 An application running on a single CPU often appears to perform many tasks at the same time. For example, a streaming audio/video
More informationChapter 4: Processes. Process Concept. Process State
Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication in Client-Server Systems 4.1 Process Concept An operating
More informationOverview. CMSC 330: Organization of Programming Languages. Concurrency. Multiprocessors. Processes vs. Threads. Computation Abstractions
CMSC 330: Organization of Programming Languages Multithreaded Programming Patterns in Java CMSC 330 2 Multiprocessors Description Multiple processing units (multiprocessor) From single microprocessor to
More informationDistributed Systems Recitation 2. Tamim Jabban
15-440 Distributed Systems Recitation 2 Tamim Jabban Project 1 Involves creating a Distributed File System (DFS) Released yesterday When/If done with PS1, start reading the handout Today: Socket communication!
More informationUNIT IV -- TRANSPORT LAYER
UNIT IV -- TRANSPORT LAYER TABLE OF CONTENTS 4.1. Transport layer. 02 4.2. Reliable delivery service. 03 4.3. Congestion control. 05 4.4. Connection establishment.. 07 4.5. Flow control 09 4.6. Transmission
More informationLe L c e t c ur u e e 7 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Multithreading
Course Name: Advanced Java Lecture 7 Topics to be covered Multithreading Thread--An Introduction Thread A thread is defined as the path of execution of a program. It is a sequence of instructions that
More informationChapter 23 Process-to-Process Delivery: UDP, TCP, and SCTP 23.1
Chapter 23 Process-to-Process Delivery: UDP, TCP, and SCTP 23.1 Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 23-1 PROCESS-TO-PROCESS DELIVERY 23.2 The transport
More informationChapter 2: Application Layer last updated 22/09/03
Chapter 2: Application Layer last updated 22/09/03 Chapter goals: conceptual + implementation aspects of network application protocols client server paradigm service models learn about protocols by examining
More informationConcurrent Processes Rab Nawaz Jadoon
Concurrent Processes Rab Nawaz Jadoon DCS COMSATS Institute of Information Technology Assistant Professor COMSATS Lahore Pakistan Operating System Concepts Concurrent Processes If more than one threads
More informationCS370 Operating Systems Midterm Review
CS370 Operating Systems Midterm Review Yashwant K Malaiya Fall 2015 Slides based on Text by Silberschatz, Galvin, Gagne 1 1 What is an Operating System? An OS is a program that acts an intermediary between
More informationInterprocess Communication By: Kaushik Vaghani
Interprocess Communication By: Kaushik Vaghani Background Race Condition: A situation where several processes access and manipulate the same data concurrently and the outcome of execution depends on the
More informationProgramming in Parallel COMP755
Programming in Parallel COMP755 All games have morals; and the game of Snakes and Ladders captures, as no other activity can hope to do, the eternal truth that for every ladder you hope to climb, a snake
More informationCS 3723 Operating Systems: Final Review
CS 3723 Operating Systems: Final Review Instructor: Dr. Tongping Liu Lecture Outline High-level synchronization structure: Monitor Pthread mutex Conditional variables Barrier Threading Issues 1 2 Monitors
More informationPart 2: Application Layer
Part 2: Application Layer Our goals: conceptual, implementation aspects of network application protocols client-server paradigm service models learn about protocols by examining popular application-level
More informationSocket programming. Complement for the programming assignment INFO-0010
Socket programming Complement for the programming assignment INFO-0010 Outline Socket definition Briefing on the Socket API A simple example in Java Multi-threading and Synchronization Example : HTTP protocol
More informationConcurrency - Topics. Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads
Concurrency - Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads 1 Introduction Concurrency can occur at four levels: Machine instruction
More informationCS 31: Introduction to Computer Systems : Threads & Synchronization April 16-18, 2019
CS 31: Introduction to Computer Systems 22-23: Threads & Synchronization April 16-18, 2019 Making Programs Run Faster We all like how fast computers are In the old days (1980 s - 2005): Algorithm too slow?
More informationMultithreading Pearson Education, Inc. All rights reserved.
1 23 Multithreading 2 23.1 Introduction Multithreading Provides application with multiple threads of execution Allows programs to perform tasks concurrently Often requires programmer to synchronize threads
More information27/04/2012. We re going to build Multithreading Application. Objectives. MultiThreading. Multithreading Applications. What are Threads?
Objectives MultiThreading What are Threads? Interrupting threads Thread properties By Võ Văn Hải Faculty of Information Technologies Summer 2012 Threads priorities Synchronization Callables and Futures
More informationIT 540 Operating Systems ECE519 Advanced Operating Systems
IT 540 Operating Systems ECE519 Advanced Operating Systems Prof. Dr. Hasan Hüseyin BALIK (5 th Week) (Advanced) Operating Systems 5. Concurrency: Mutual Exclusion and Synchronization 5. Outline Principles
More informationCS 5520/ECE 5590NA: Network Architecture I Spring Lecture 13: UDP and TCP
CS 5520/ECE 5590NA: Network Architecture I Spring 2008 Lecture 13: UDP and TCP Most recent lectures discussed mechanisms to make better use of the IP address space, Internet control messages, and layering
More informationOperating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy
Operating Systems Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. AL-AZHAR University Website : eaymanelshenawy.wordpress.com Email : eaymanelshenawy@yahoo.com Reference
More informationUDP and TCP. Introduction. So far we have studied some data link layer protocols such as PPP which are responsible for getting data
ELEX 4550 : Wide Area Networks 2015 Winter Session UDP and TCP is lecture describes the two most common transport-layer protocols used by IP networks: the User Datagram Protocol (UDP) and the Transmission
More informationCS2 Advanced Programming in Java note 8
CS2 Advanced Programming in Java note 8 Java and the Internet One of the reasons Java is so popular is because of the exciting possibilities it offers for exploiting the power of the Internet. On the one
More informationTransport Layer. Gursharan Singh Tatla. Upendra Sharma. 1
Transport Layer Gursharan Singh Tatla mailme@gursharansingh.in Upendra Sharma 1 Introduction The transport layer is the fourth layer from the bottom in the OSI reference model. It is responsible for message
More informationUnit 1 Java Networking
Q1. What is Server Socket? Discuss the difference between the Socket and ServerSocket class. The ServerSocket class (java.net) can be used to create a server socket. This object is used to establish communication
More informationIntroduction to Sockets
Introduction to Sockets Sockets in Java 07/02/2012 EPL 602 1 Socket programming Goal: learn how to build client/server application that communicate using sockets Socket API o introduced in BSD4.1 UNIX,
More informationOutlines. Networking in Java. Internet hardware structure. Networking Diagram. IP Address. Networking in Java. Networking basics
G52APR Application programming Networking in Java Michael Li http://www.cs.nott.ac.uk/~jwl/g52apr Outlines Networking basics Network architecture IP address and port Server-client model TCP and UDP protocol
More information