SlideServe
Menu
Préférences
© SlideServe · v2026

Java Network Programming 4

gwendolyn-colon avatar
12 diapositives · 248 Views · Oct 27, 2014

Dive into the essentials of Java Network Programming, focusing on the interplay between processes, multithreading, and context switching in operating systems. This guide explores various approaches to implement threading in Java, including extending the Thread class and implementing the Runnable interface. Learn how to create a simple client-server application that communicates over a specific port, handling integer inputs and demonstrating multi-threaded server processing. By the end, you’ll understand the foundation of network services and concurrent programming in Java.

Java Network Programming 4 - slide 1
01 / 12Java Network Programming 4
1 / 17

Télécharger la présentation

Java Network Programming 4
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Java Network Programming 4 352362 – Network Operating Systems and Protocols ChoopanRattanapoka

  2. MultiTasking proc1 proc2 proc3 CPU การทำงานปกติ(ง่ายๆ) ให้คิดถึง 1 application = 1 process CPU รุ่นที่มี core เดียวจะทำงานได้ทีละ 1 process เพราะฉะนั้นที่เราเห็น process หลายตัวทำงานพร้อมกันได้ จะมีระบบที่เรียกว่า context switch ที่ OS จะเลือก process ขึ้นมาใช้งานกับ CPU

  3. Multi Tasking Programming Service Process Server Process Service Process Service Process

  4. Multi Threading Server process Service Thread Service Thread Service Thread

  5. Java Thread Programming • ใน Java สามารถจะเขียน Thread ได้ 2 แบบ • ใช้ extends Thread import java.lang.*; public class Counter extends Thread { public void run() { .... } }

  6. Java Thread Programming • ใช้ implements Runnable import java.lang.*; public class Counter implements Runnable{ public void run() { .... } }

  7. Example 1 : Runnable

  8. Example 1 : Runnable (ต่อ)

  9. Example 2 : Thread

  10. Example 3 : Single Thread

  11. Example 4 : Multi Thread

  12. Exercise • จงเขียนโปรแกรม Client – Server • Server • ให้บริการที่ port หมายเลข 5432 • เป็นการทำงานแบบ multi thread • จะรับค่าตัวเลขจำนวนเต็มจาก Client แล้วจะหยุดการทำงานเป็นวินาทีที่กำหนด • จากนั้นส่งคำว่า Hello กลับ • Client • โปรแกรมจะรับจำนวนเต็ม 1 ตัวจาก command line • ติดต่อกับ Server โดยจะส่งจำนวนเต็มที่รับมาจาก command line ให้ server • Client จะรอรับข้อความจาก Server ก่อนปิดการเชื่อมต่อ • ให้เขียนทั้งแบบที่ใช้ implements Runnableและ xtends Thread