Thread in TCP
Thread in TCP
Thread in TCP
Week 6
Program Studi Teknik Informatika
Fakultas Teknik – Universitas Surabaya
What is Thread?
What is Thread?
• Short for a thread of execution. Threads are a way for a program to
divide (termed "split") itself into two or more simultaneously (or
pseudo-simultaneously) running tasks.
• Java is the first programming language that use threading in this
environment
• Example Application:
– Access browser with multiple tabs
– Webserver handles many request from multiple PC/device
• Source: https://simple.wikipedia.org/wiki/Thread_(computer_science)
LifeCycle a Thread
Thread Status “new”
Thread Status
“Runnable”
LifeCycle a Thread
"Runnable" threads may change to
"timed waiting" for a certain period.
Status will return to "runnable" when
the time is up
1. implements Runnable
2. extends Thread
Using “implements Runnable”
• Create a class "Worker“ that implements runnable
Using “implements Runnable”
• Make the function "default" run
• Make the function start ()
Using “implements Runnable”
Using “extends Thread”
• Create a class "WorkerThread“
extends Thread
Using “extends Thread”
What is the difference
between "Runnable
implements" and
"Extends Thread"?
Implementation (2)
30 Minute
Simple Chat Using TCP
• Open the previous
project, namely simple
chat (Week 6)
The result of
moving the Baris ini berguna untuk
clientSocket object membuat thread dan
menjalankannya
RESULT
Any Question ?