Professional Documents
Culture Documents
Network Programming
Network Programming
Network Programming
Lecture 08
Threads
Ransara Wijethunga
Tech. Lead
Millennium IT
2016 – 09 - 24
References / Recommended Textbooks
2
Overview
This lecture provides the introductory knowledge
for usage of threads in industry standard
applications. Then, this lectures covers inter
process/thread communication as well.
3
Introduction
Most non-trivial programs involve some
form of inter-process communication (IPC).
This is a natural effect of the design principle
that the better approach is to design an
application
◦ as a group of small pieces that communicate with
each other,
◦ instead of designing one huge monolithic
program.
4
How Applications are Designed…
Historically, applications have been built in the following
ways:
◦ One huge monolithic program that does everything. The
various pieces of the program can be implemented as functions that
exchange information as function parameters, function return values,
and global variables.
6
FTP in 1990s… (cont.)
The problem was that both the FTP servers bundled
with most Unix boxes and the third-party FTP servers,
forked a new process for each connection.
11
Processes
A process has a self-contained execution environment.
A process has a complete, private set of basic run-time
resources.
Each process has its own memory space.
13
Threads
Threads are sometimes called lightweight processes.
Both processes and threads provide an execution
environment, but creating a new thread requires fewer
resources than creating a new process.
15
1. Providing a „Runnable‟ Object
The Runnable interface defines a single
method, run, meant to contain the code
executed in the thread.
The Runnable object is passed to the
Thread constructor
Apply Threads
( by implementing runnable)
20
Our Previous Code
21
Questions For Coming Week:
Java Process Builder class.
Thread management with Java Executor.
◦ http://docs.oracle.com/javase/tutorial/essential/concurrency
/highlevel.html
CMPT300 Videos : 7. SFU CMPT 300: Processes &
Threads in Operating System
◦ http://www.youtube.com/watch?v=gif8znTA1Jw
Thread Synchronization
22
Questions
If failed, email me
◦ ransaraw@gmail.com
23