COMP1549 Week 3
COMP1549 Week 3
Dr Taimoor Khan
https://mtaimoorkhan.github.io
https://www.isec.group
2. Send data
3. Receive data
4. Close a connection
5. Bind to a port
Active thread
scheduled
runnable running
Ex s
)
t(
or
it to
a r
s p(
t
ted
s
ru )
I/
n(
O
ues
)
notify()
av
notifyAll() wait()
req
ai
new time is up sleep() dead
la
new
I/O
resume() suspend()
t = new Thread(); bl
e
blocked
}
◉ Shared Object’s code is executed by two
different Threads
COMP1549: Advanced Programming 30
Shared objects Java memory model
methodTwo() methodTwo()
Local Variable 1 Local Variable 1
www.javaworlld.com
Heap
JVM
How come the threads can be run again after they finish?
• There’re not!
• New threads are created each time Go
is pressed
• But all are sharing the same Shared2
object
CountDown2
CountUp2
run() {
Shared2 run() {
int counter
increment() {
}
}
}
decrement() {
java.util.concurrent
◉ Class ReentrantLock supports explicit locking