TELKOM
NIKA
, Vol. 11, No. 9, September 20
13, pp.
5395
~54
0
1
ISSN: 2302-4
046
5395
Re
cei
v
ed Ma
rch 5, 2
013;
Re
vised J
une
14, 2013; Accepte
d
Ju
ne
24, 2013
A Framework of Concurrent Mechanism Based on Java
Multithread
Wuxu
e Jian
g*
1
, Qi Li
2
,
Z
h
iming Wang
3
, Jianfeng
Luo
1
1
Departme
n
t of Computer En
g
i
ne
erin
g, Don
g
gua
n
Pol
y
tec
h
nic, Don
g
g
uan
523
80
8, Guan
gdo
ng, Ch
ina
2
Departme
n
t of Computer a
n
d
Information, H
uai
hua V
o
ca
tio
nal a
nd T
e
chni
cal Col
l
e
ge, Hu
aih
ua 4
180
00,
Hun
an, Chi
n
a
3
Educatio
nal T
e
chn
o
lo
g
y
Ce
n
t
er, Dongg
ua
n Pol
y
t
e
ch
nic, D
ong
gu
an 52
38
08, Guan
gdo
n
g
, Chin
a
*Corres
p
o
ndi
n
g
author, e-ma
i
l
: 4428
45
85@
q
q
.com
A
b
st
r
a
ct
T
he co
ntinu
o
u
s
ly incr
eas
ed
de
ma
nd for
pa
ralle
li
ng
mu
ltitask in
dom
a
ins
such as
grid c
o
mputi
ng
and
clo
u
d
co
mp
utin
g h
a
s s
i
gnific
antly
pr
o
m
ote
d
r
e
se
arch o
n
c
oncurr
e
nt mech
anis
m
an
d c
oncurr
e
nt
progr
a
m
min
g
. T
he Java pr
ogr
amming
lan
g
u
age su
pp
orts mu
ltithre
ad
me
chan
is
m for de
velo
pin
g
par
all
e
lin
g
progr
a
m
s, how
ever, it is difficult to apply Ja
va concur
r
ent pri
m
itives to s
pecific pro
b
l
e
ms. T
hus, for
the
deve
l
op
ment
of high re
lia
bl
e and q
u
a
litat
ive Java
co
nc
urrent pro
g
ra
ms, this pa
pe
r analys
es Ja
va
mu
ltithre
ad
mecha
n
is
m
an
d
it
’
s
re
ali
z
a
t
i
on, st
ud
ies t
he c
oncurr
ent
mech
anis
m
base
d
o
n
J
a
va
synchro
ni
z
a
ti
o
n
an
d inter
a
cti
v
e co
mmun
icat
ion
mec
h
a
n
is
m, comp
ares th
e
concu
rre
nt structure b
a
sed
o
n
oper
ating syst
em
and bas
ed on Jav
a
m
u
lt
ithread,
sum
s
up
some
conc
urrent pr
ogramm
i
ng rules
and
strategies
to
pr
event
de
adl
ock
.
A fra
m
e
insta
n
ce
bas
ed on
entire
synchr
o
ni
z
a
ti
on is pres
ented,
w
h
ich
c
a
n
hel
p to deve
l
op
concurre
nt pro
g
ra
ms qu
ickly.
Ke
y
w
ords
:
jav
a
mu
ltithre
ad, concurr
ent
me
chan
is
m, synchron
i
z
a
tio
n
me
chan
is
m, dea
dl
ock preca
u
tio
n
Copy
right
©
2013 Un
ive
r
sita
s Ah
mad
Dah
l
an
. All rig
h
t
s r
ese
rved
.
1. Introduc
tion
With the
con
s
tantly adva
n
c
eme
n
t of th
e mo
dern o
p
e
rating
syste
m
empl
oyed
a kernel-
level multithreadin
g
struct
ure a
nd a
r
chitecture
of the pro
c
e
s
so
r, con
c
u
r
rent
prog
rammi
n
g
techni
que
s a
l
so sprang u
p
and o
c
cup
i
ed a pivotal
position in
the real
-worl
d
appli
c
ation
s
.
Curre
n
tly, the lang
uag
e d
e
velopme
n
t tools li
ke
C++, Delphi,
Jav
a
etc. a
r
e
all
sup
p
o
r
ting t
h
e
c
o
nc
ur
re
n
t
mu
lti-
ta
sk
ing program [1, 2].
Java was o
ne of the first lang
uag
e
s
to make
multithrea
din
g
easily ava
ilable to
develop
ers
and
provid
e
d
built-i
n p
r
imitives fo
r threa
d
s,
such
a
s
wait(), n
o
tify(),
and
synchro
n
ized
() etc. [3, 4], but
those are not sufficie
n
t for so
me con
c
u
r
rent
progra
mming, and
even ca
n not solve some sophi
st
icate
d
concurren
c
y issue
s
.
The
Java la
n
guag
e an
d Java virtual m
a
chi
ne h
a
ve
provide
d
a
completely
se
nse
of the
multi-thre
ad
mech
ani
sm,
its built-in
lang
uag
e-le
vel
multi-th
read me
chan
ism ca
n
e
a
s
ily
impleme
n
t development of parall
e
l pro
g
rams of mu
ltip
le-task [5, 6].
Java multithread me
cha
n
i
s
m
has
achieve
d
sim
u
ltaneo
us exe
c
utio
n
of mult
i-ta
sk in m
a
cro
and p
r
ovide
d
syn
c
h
r
ono
us
mech
ani
sm
s and comm
uni
cation
m
e
cha
n
ism
s
for achi
eving
critical re
sou
r
ce p
r
otectio
n
du
ri
ng
the con
c
u
r
ren
t
proce
s
s, also provide
d
preventiv
e mea
s
ures of de
ad
lock due to sy
nch
r
oni
zatio
n
.
2. Process a
nd Thread
2.1. Conce
p
t Comparison
The process is a static co
de
that the progra
m
con
d
u
c
ts a dynami
c
run
n
ing p
r
o
c
e
ss o
n
the pro
c
e
s
so
r, it’s a process
of gen
eration, develo
p
ment an
d
e
x
tinction. Thread is
a sm
aller
executio
n uni
t than the pro
c
e
ss,
there may have one or more threa
d
s in one p
r
o
c
e
ss, thre
ad i
s
also a dyn
a
m
i
c pro
c
e
s
s of cr
e
a
tion, existence a
nd de
mise.
2.2. Functio
n
s Compa
r
is
on
The th
read
is an im
porta
nt part
of the p
r
oces
s. T
he t
r
adition
al p
r
o
c
e
s
s wears t
w
o h
a
ts:
as th
e b
a
si
c
unit of resou
r
ce
allo
cation
and
CPU sch
edulin
g, sepa
rate it
s fun
c
ti
on a
nd
sh
are
it
Evaluation Warning : The document was created with Spire.PDF for Python.
ISSN: 23
02-4
046
TELKOM
NIKA
Vol. 11, No
. 9, September 201
3: 539
5 – 5401
5396
with entities
called thre
ad
s in orde
r to be
tter ca
rry out con
c
u
r
ren
c
y of the develo
p
ment progra
m
and allo
w th
e pro
c
e
s
s to
get rid of the bu
rde
n
so
me task, the
n
threa
d
is
come i
n
to b
e
ing.
Process i
s
a
basi
c
u
n
it for
resou
r
ce allo
cation,
a
nd th
read i
s
a
ba
si
c unit of the
CPU
sched
uli
n
g
.
Processe
s
a
pply and
obt
ain the
re
quired resource
s, the corresp
ondi
n
g
threa
d
s
active in
these
resou
r
ces a
n
d
use them.
2.3. Sy
stem
Ov
erhead Comparison
Overhe
ad of
co
nversion
and ch
angin
g
-ove
r b
e
tween th
rea
d
s is
small
e
r
than the
overhe
ad n
e
eded fo
r the
pro
c
e
s
ses do
ing the
sam
e
amou
nt of work be
ca
use
of the differe
nce
betwe
en an
d
thread
s in t
he above
-
me
ntioned fun
c
t
i
ons, an
d it’s easie
r to im
plement mult
i-
thread
synchronization an
d
commu
nication.
3. Thread State an
d Con
t
rol Method
Java threads have a dyna
mic life cycle,
a complete
cycle
will go through five states [7],
conve
r
si
on b
e
twee
n threa
d
s an
d the co
rre
sp
ondi
ng
threa
d
co
ntrol
method sho
w
n in Figure 1.
Figure 1. Thread’
s State Conv
ention a
n
d
Control Met
hod
3.1. Ne
w
Bor
n
State
The
obje
c
t i
s
in a
ne
w
born
state
after creati
ng th
e in
stance
of
a
su
bcla
ss of
the
thread
cla
ss a
nd initi
a
lizatio
n, corresp
ondi
ng st
orag
e sp
ace and process
resou
r
ce
s a
r
e created by
this
time.
3.2. Runnabl
e State
The threa
d
is in runnabl
e state after st
arting
the ne
w born threa
d
, it is in
the
runn
able
queu
e to wait
for the arrival
of the CPU time
slice. Run
n
ing conditio
n
is existed n
o
w.
3.3. Running
State
The th
rea
d
s i
n
runn
able
st
ate get
CP
U
time sli
c
e
an
d come
into
a runni
ng
sta
t
e, then
perfo
rm the run () m
e
thod
cod
e
of corre
s
po
ndin
g
thre
ad to compl
e
te the approp
riate action.
3.4. Blocked
State
The thre
ad
s in runni
ng or runna
ble state
abdicate the
CPU and su
spe
nd the executio
n
that
is
to ente
r
a blo
c
ked state
for som
e
rea
s
on,
co
nvert to
runn
abl
e or ru
nnin
g
state o
n
ly wh
en
the blocke
d cause are
rem
o
ved.
3.5. Dead State
A thread
co
mpleted all o
f
its operatio
ns o
r
fo
rcibly
terminated i
s
in a de
ad
state, the
thread
can n
o
t
be resto
r
ed
and exe
c
uted
.
Evaluation Warning : The document was created with Spire.PDF for Python.
TELKOM
NIKA
ISSN:
2302-4
046
A Fram
ework of Concurren
t
Mechani
sm
bas
ed on
Ja
va Multithrea
d (Wuxu
e
Jia
n
g
)
5397
4. Thread Cr
eation ba
sed
on the Thre
a
d Subclass
and Run
n
abl
e
Interface
It usually req
u
ire
s
more than one ta
sk
simultan
eou
sl
y perform in
macro, also need
s to
take full a
d
va
ntage of the
system
re
sou
r
ce
s a
nd
im
p
r
oves th
e p
r
o
g
ram
execution efficie
n
cy
in
large utility software devel
opment
process,
multi-th
read can
provide
excellent solution. Java is
a
compl
e
te se
nse
of pro
g
ramming la
ng
uage o
r
ie
nte
d
to the obj
ect, provid
es abund
ant cl
ass
libra
rie
s
an
d
appli
c
ation i
n
terface
s
to
a
c
hiev
e
u
s
er-f
riendly devel
opment and
utilization.
T
h
ere
are two
ways
to creat
e thre
ads in
Java [8].
4.1. Inherit the Threa
d Cl
ass
Java. lan
g
. Threa
d
is
a cl
ass u
s
ed to
repr
e
s
e
n
t the
pro
c
e
ss
provided by the
system,
many metho
d
s
in T
h
re
ad
cl
ass p
r
ovide
a
com
p
lete
mu
lti-threa
d
p
r
ocessing fu
nctio
n
. Thre
ad
ca
n
define the su
bcla
ss and
co
nstru
c
t u
s
ers
thread.
Suc
h
as
:
publi
c
MyThread ex tend
s Thre
ad
{
/ / Related propertie
s
an
d method
s defi
n
ition
publi
c
void ru
n()
{
, /
/ Thread b
ody cod
e
}
publi
c
static v
o
id main (Stri
ng arg
s
[])
{Thread t = n
e
w MyTh
read
();
And
t. s
t
art(); / / St
art the thread t
,
}
}
Run
()
metho
d
is e
s
sential
and it i
s
the
core
of the
whole th
read, t
he code i
s
th
e co
ntent
to be execute
d
by the threa
d
, start() method
calls the
run
() meth
od
to start the thread.
4.2. Complete R
unnable Interface
Java
provid
e
s
a
runna
ble
interfa
c
e
which
c
an
ach
i
eve the
goa
l of multithre
ad, this
interface only
has
one
ru
n() metho
d
, uses
can
overl
o
ad this
metho
d
to co
mplete
relate
d thre
a
d
operation
s
, ru
nnabl
e interfa
c
e can be a
u
tomatica
lly ide
n
tified and pe
rforme
d by the system.
For exampl
e:
publi
c
cla
s
s My Thread im
plement
s Ru
nnabl
e
{
, /
/ Related a
ttribute definitions
publi
c
void ru
n()
{
, /
/ Code to be execute
d
b
y
the thread
}
}
There are two ways to sta
r
t, but the
es
sence is
of the s
a
me, as
follows
:
MyThrea
d
my = new MyTh
read();
Thre
ad t = ne
w Thread (my);
t. s
t
art();
or
MyThrea
d
my = new MyTh
read();
new Th
re
ad(my).start.
4.3. Compari
s
on of T
w
o
Metho
d
s of
Thread
Crea
tion
The first method is
distin
ct
ive nuan
ce, l
ogic
cl
ea
r an
d easy to u
s
e
,
it achieves
Run
nable
interface in
e
s
sen
c
e; the
seco
nd m
e
tho
d
can m
a
ke
u
p
the
sho
r
tag
e
of the first
method, that
can
achi
eve mult
iple inh
e
rita
n
c
e
(Java
cla
s
ses onl
y can
a
c
hieve
singl
e
inh
e
rit
ance), su
ch as
appli
c
ation
s
i
n
the
sm
all p
r
og
ram
of Ap
plet. The
Run
nable
interfa
c
e al
so i
s
a
c
hi
eved b
a
sed
o
n
the Thre
ad cl
ass frame
w
o
r
k.
Evaluation Warning : The document was created with Spire.PDF for Python.
ISSN: 23
02-4
046
TELKOM
NIKA
Vol. 11, No
. 9, September 201
3: 539
5 – 5401
5398
5. Analy
s
is a
nd Stud
y
of the Jav
a Concurren
t
Mec
h
anism
5.1. Mutually
Exclusiv
e Mechanis
m ba
sed on Sy
nc
hronize
d an
d Monitor
The intro
d
u
c
tion of co
ncurrency, in orde
r to
achieve
some ki
nd of real obje
c
tive in multi-
prog
ram
m
ing
,
there al
way
s
have
som
e
prog
ra
m
se
gment that can’t be “sim
u
l
taneou
sly”
(the
essen
c
e is
simultaneo
usly
in macro
)
acce
ssed by
more than
two threa
d
s,
that is critical
resou
r
ce. Ja
va defines t
he critical re
sou
r
ces
usin
g synchronized to lock the mark, critical
resou
r
ces
he
re
may
b
e
a
m
e
thod or a co
de segm
ent. The
m
e
thod
or cod
e
seg
m
ents marke
d
b
y
synchro
n
ized
in the
p
r
og
ram
can
only
be a
c
ce
ssed
by one
threa
d
at a
n
y time
, that mutu
a
lly
exclu
s
ive a
c
ce
ss to
critical
re
sou
r
ce
s is a
c
hieve
d
. It has in
trodu
ced
Mo
nitor
similar to
sema
pho
re m
e
ch
ani
sm in t
he realization
prin
cipl
e,
Ja
va assign
ed
each obj
ect a
Monitor,
and
its
role
wa
s re
spon
sible
for
managi
ng th
e thread’
s
acce
ss to
criti
c
al resource
s.
A thread
ge
tting
acce
ss to a
certai
n critica
l
resou
r
ce
wi
ll obtai
n the
Monitor
of the su
bordinat
e obje
c
t of the
critical re
so
urce, and the
Monitor
will “l
ock”, ot
he
r thread
s who would lik
e to have acce
ss t
o
the
critical resour
ces must wait
till the Monitor
“unlocked”
(see Figure 2).
Figure 2. Rea
lization Sche
matic of
Lo
cked-u
n
lo
cked
Mutex Mech
a
n
ism
5.2. Interac
t
iv
e
Communication Me
ch
anism Sased
on
w
a
i
t
() an
d notif
y
()
Synchroni
zed
has solve
d
the mut
ually exclusive a
c
ce
ss i
s
sue
s
for the criti
c
al re
source
s,
it
also req
u
ires colla
borative
wo
rk bet
wee
n
thr
ead
s in
real
-worl
d
appli
c
atio
n
s
, that cond
u
c
ts
mutually excl
usive a
c
ce
ss to t
he critica
l
re
sou
r
ces,
mean
while, t
he thread
s al
so
comm
uni
cate
with e
a
ch oth
e
r. Su
ch
as classic produ
cer-co
ns
ume
r
issue
s
, writers
- read
ers i
s
sue
s
,
sen
der–
receiver i
s
su
es i
n
net
wo
rk tran
smi
ssi
on
and
so
on.
Java provide
s
three
sta
nda
rd O
b
je
ct cl
a
ss
method
s in
order to
solve the inte
ra
ction
pro
b
le
m
s
b
e
twee
n the
mul
t
i-thre
ad
: w
a
it(
)
,
no
tify(
)
a
nd
notifyAll(). Wait() meth
od i
s
to convert t
he ru
nnin
g
st
ate to the bl
ocked
state f
o
r the
cu
rre
n
t
ly
runni
ng th
rea
d
, wait()
ente
r
ed th
e
waitin
g qu
eue
co
ncentrate
s
a
nd relea
s
e
s
th
e Monitor; notify()
is to wa
ke
u
p
the first thread in the
q
ueue of
the
wait() concen
tration (or
wake
up a thread
according to
certai
n algo
ri
thms), so tha
t
conv
ert the
thread’
s blo
c
ked state to
runnin
g
stat
e;
notifyAll() is to wa
ke up al
l the thread
s centra
lized b
y
wait(). Co
-use
of wait()
and notify()
can
easily a
c
hi
eve the mutu
all
y
exclusive
communi
catio
n
me
chani
sm
, so that to eff
e
ctively solve
the
above cite
d p
r
oble
m
s.
5.3. Compari
s
on of Sy
nc
hroniza
tion
based on Mu
tex an
d Jav
a
Sy
nchronized
Con
c
u
r
ren
c
y mean
s multip
le thread
s wait for each
other an
d co
mmuni
cate with each
other in som
e
of the key points. Jav
a's sy
n
c
h
r
o
n
i
z
ed h
a
s a
c
h
i
eved a mutually exclu
s
ive
mech
ani
sm
of the threa
d
, wait() an
d notif
y() ha
ve achi
eved
a messa
g
e
comm
uni
cat
i
on
mech
ani
sm
betwe
en the
thread
s, th
ey solved th
e pro
b
lem o
f
data con
s
i
s
ten
c
y and t
he
colla
boration
betwee
n
the multi-thread re
sp
ecti
vely, and realized com
p
lete se
nse
of
con
c
u
r
ren
c
y. Figure 3 m
a
kes a
sim
p
le
compa
r
ison
b
e
tween Java’
s
synchro
n
ization
me
ch
anism
and
synchro
n
izatio
n me
chani
sm of
si
gnal la
mp a
nd P, V pri
m
itives’ re
ali
z
ation
at op
erating
system
-level.
Evaluation Warning : The document was created with Spire.PDF for Python.
TELKOM
NIKA
ISSN:
2302-4
046
A Fram
ework of Concurren
t
Mechani
sm
bas
ed on
Ja
va Multithrea
d (Wuxu
e
Jia
n
g
)
5399
Figure 3. Co
mpari
s
o
n
of Synchroni
zati
on Mec
hani
sm betwee
n
Java and the
Operating System
6. A Rou
t
ine of Con
c
urr
e
nt Multita
sk
based on F
u
ll S
y
nchronizatio
n
6.1. Practical
Routine
s
Con
s
tru
c
t a
sha
r
ed
buffer zon
e
cl
ass
Share
d
Buffer, there i
s
rel
a
ted data
attribute
s
within it, that is one
sen
d
() method an
d one re
ce
ive
(
) method, bot
h are
synchronized metho
d
s,
and achieve
intera
ctive co
mmuni
cation
between th
em throu
gh wait() and n
o
tify(). Con
s
truct
anothe
r
two sub
-
cl
ass
Se
nder and Re
ceiver whi
c
h
were
inh
e
rit
ed
from
th
e Thre
ad cla
s
s,
to
achi
eve sp
ecific sen
d
ing
and re
ceivin
g operat
ion
by generatin
g two threa
d
s
of t1 and t2.
Routin
es a
r
e
as follo
ws:
publi
c
cla
s
s FrameSa
m
ple
{
publi
c
static v
o
id main
( String arg
s
[ ] )
{
SharedBuffer buffer=
ne
w
SharedBuffer( ) ;
Sende
r t1= n
e
w Send
er( b
u
ffer) ;
Re
ceiver t2
= new
Re
ceiver( buffer) ;
t1. s
t
art( ) ;
t2. s
t
art( ) ;
}
} / / Main class Fra
m
eSam
ple, buffer is
sha
r
ed o
b
je
ct instan
ce
cla
ss Sen
d
e
r
extends Th
re
ad
{ Share
d
Buffer theBuffer;
publi
c
Sende
r( Share
d
Buffer s)
{ theBuffer=
s; }
publi
c
void ru
n( )
{ cha
r
c;
for( int i=
0; i< 5; i+
+
)
{ c=
( ch
ar
) ( Math. rand
o
m
( ) * 26+
-A. ) ;
theBuffer. s
e
nd( c) ;
Sys
t
em . out.
println(/ Sender: 0+
c
)
;
}
}
} / / Sender cl
ass
cla
ss
Re
ceiv
er ex tends T
h
rea
d
{ Share
d
Buffer theBuffer;
publi
c
Re
ceiv
er( Sha
r
e
d
Bu
ffer s)
{ theBuffer=
s; }
publi
c
void ru
n( )
{ cha
r
c;
for( int i=
0; i< 5; i+
+
)
{ c
=
theB
uffer. rec
e
ive( ) ;
Sys
t
em . out.
println(/ Rec
e
iver: 0 +
c
)
;
}
}
} / / Rec
e
iver
c
l
as
s
c
l
as
s
Sh
ar
edBu
ffe
r
{ private int index= 0;
Evaluation Warning : The document was created with Spire.PDF for Python.
ISSN: 23
02-4
046
TELKOM
NIKA
Vol. 11, No
. 9, September 201
3: 539
5 – 5401
5400
private ch
ar b
u
f[ ] = new ch
ar[ 5] ;
publi
c
syn
c
hronized void send(
cha
r
c)
{ while
( index
= = buf. lengt
h)
{ try { this
. wait( ) ; }
catch( Interru
p
tedEx ceptio
n e) { }
}
this. notify( ) ; buf[ index] = c; index+
+ ;
}
publi
c
syn
c
hronized char
receive
(
)
{ while
( index
= = 0)
{ try { this
. wait( ) ; }
catch( Interru
p
tedExceptio
n e) { }
}
this. notify( ) ; index - - ; return buf[ index
] ;
}
} / / Shared buffer zo
ne cla
ss.
6.2. Some Explana
t
ions
a)
Program in
stance owns a
co
mpl
e
te se
n
s
e of co
ncurrency
For the mutu
ally exclusive
access to the sha
r
ed b
u
ffer zon
e
, it is through
wait
() an
d
notify() to co
mmuni
cate
with each othe
r that
wh
ethe
r you can
se
nd data to th
e buffer
zon
e
and
fetch d
a
ta from the
buffe
r zone.
Co
m
p
lete
routine
co
de
wa
s b
a
se
d o
n
Win
dows
2003
a
nd
JDK1.5
environment; if yo
u do
not u
s
e
the syn
c
h
r
o
n
ize
d
to a
c
hi
eve mutually
exclu
s
ion i
n
t
he
example, there will be e
r
rors of data lo
ss and du
plicati
on, abno
rmal
situation
will appe
ar a
nd th
e
efficien
cy of the CPU
will significa
ntly reduc
e without
the use of
wait() an
d notify().
b)
Dee
p
und
erstandin
g
to criti
c
al re
so
urce
s
The critical reso
urce
s refe
r to som
e
sh
ared
equi
pm
ent, sha
r
ed
d
a
ta se
gment
and data
stru
cture etc.
in the real
world,
an
d critical resource
in the routin
e
is the buffer.
The comput
er
worl
d is
an a
b
stra
ction
an
d pa
ckagin
g
of the re
al
world, it’s
determined by
spe
c
ific m
e
ch
ani
sm,
the corre
s
p
o
n
d
ing critical
reso
urce
s are cod
e
se
gmen
ts of the prog
ram, and they
are se
nd
() a
nd
receive() met
hod
s corre
s
p
ondin
g
to the
routin
es
. Su
bstan
c
e
s
in
two
wo
rld
s
a
r
e interco
nne
cted
and co
nsi
s
te
nt in esse
nce, the reaso
n
why the
buffer is criti
c
al resource i
s
manife
sted
and
reali
z
ed th
rou
gh ope
ration
s of send
() an
d receive() m
e
thod
s.
7. Precautio
n
of De
adloc
k
Such a p
hen
omeno
n may
occur in th
read syn
c
h
r
o
n
izatio
n me
chani
sm that several
thread
s ea
ch
own
s
some o
f
the resou
r
ce
s req
u
ir
ed, bu
t still need so
me of
the resource
s of other
thread
s at th
e sam
e
time, and they wa
it for the
rele
ase of othe
r
thread
s, othe
rwi
s
e they are
unabl
e to push ahe
ad, su
ch a stale
m
a
t
e phenom
en
on due to co
mpetition an
d allocatio
n
of
resou
r
ces is
calle
d d
eadlo
c
k [9, 10]. T
h
e Java
con
c
u
rre
ncy m
e
cha
n
ism
ba
sed
o
n
the
JVM l
e
vel
is simil
a
r to
the syn
c
hron
ization m
e
ch
anism
of the
operating system, deadl
ock is of g
r
eat
hidde
n, it may easily l
e
a
d
to de
adlo
c
k failu
re
s
wh
en u
s
e
r
s u
s
e it, and
Jav
a
can n
o
t av
oid
deadl
ock an
d re
cove
r de
adlo
ck, the
o
n
ly resolution
is to take p
r
ecaution
s
a
gain
s
t deadl
ock
whe
n
use it. A number o
f
methods a
nd strate
gie
s
provided b
e
l
ow can be
use
d
to prev
en
t
deadl
ocks.
7.1. Partition
of Thread T
asks mus
t
b
e
Clear an
d Rea
s
onable
Multithrea
d concurren
c
y has be
com
e
the root
cau
s
e
of deadlo
ck,
so you must
combi
ne
with the a
c
tu
al need
s a
n
d
Java’s m
u
ltithrea
d me
cha
n
ism
cha
r
a
c
teristi
cs to
rea
s
on
ably arran
g
e
the tasks of e
a
ch thread; e
n
su
re bal
an
ced re
sou
r
ce
s; try to reduce
the numbe
r o
f
thread
s [10].
7.2. Properly
use the Sy
n
c
hronization
Mechanism
The u
s
e of
synchro
n
ized
is the direct
reason for gene
rating
use
r-l
evel de
adlo
ck,
carefully co
n
s
ide
r
the
cal
l
betwe
en th
e syn
c
hroni
zation metho
d
s
; try to avoid ne
sted ca
ll
betwe
en the
synchro
n
ization method
s.
Evaluation Warning : The document was created with Spire.PDF for Python.
TELKOM
NIKA
ISSN:
2302-4
046
A Fram
ework of Concurren
t
Mechani
sm
bas
ed on
Ja
va Multithrea
d (Wuxu
e
Jia
n
g
)
5401
7.3. Properly
use the
Co
mmunicatio
n Mechanis
m
We u
s
ually m
a
ke p
a
rin
g
use of wait() a
n
d
not
ify() for the two meth
o
d
s a
r
e able t
o
solve
certai
n dea
dl
ock pro
b
lem
s
, and con
s
id
e
r
wheth
e
r to u
s
e notifyAll()
method when
nece
s
sary.
7.4. Ensure the Critic
al Resourc
es to
be Re
fined
Critical
re
so
urce i
s
th
e
material
ba
se cau
s
ing
d
eadlo
c
k, try
to refin
e
the
critical
resou
r
ces in
orde
r to red
u
c
e conflict du
e to competiti
on of re
sou
r
ces [11].
8. Conclusio
n
The po
we
rful
multithread
technol
ogy provide
s
terri
f
ic solving
st
rategie
s
of realisti
c
probl
em
s for the users’
multitask pro
g
rammi
ng. T
he pa
per di
scusse
d the
impleme
n
tation
techni
que
of
the
Java m
u
ltithread
me
cha
n
ism
fro
m
the p
o
int
of view
of th
e pri
n
ci
ple
s
and
appli
c
ation
s
,
analyzed the
syn
c
hrono
u
s
commu
nication p
r
obl
e
m
s in
multithrea
d te
chn
o
l
ogy
based on th
e ope
rating
system level,
summa
ri
zed
some d
eadl
ock precauti
on metho
d
s
and
strategi
es,
an
d co
nst
r
u
c
ted
a frame
w
o
r
k
instan
ce
of a
fully synch
r
on
ized
co
ncurre
nt multitask. A
high-relia
bility and hig
h
-qu
a
lity con
c
urre
nt prog
ram
can be d
e
velo
ped qui
ckly in real
softwa
r
e
developm
ent pro
c
e
ss a
c
co
rd
ing to the framework.
Ackn
o
w
l
e
dg
ements
This work was suppo
rted
by Science
and Techn
o
logi
cal Prog
ram for Don
ggua
n’s
High
er Ed
ucation, Scie
nce and
Re
se
a
r
ch,
and
He
a
l
th Ca
re In
stitutions(No.2
0
1110
8101
010
),
and by Gua
n
gdon
g Provin
ce Hi
gh-te
ch
I
ndustri
a
l Proj
ects(No. 201
2B0101
000
5
0
).
Referen
ces
[1]
Hon
g
w
e
i Li
ao,
Yin W
a
n
g
, H
y
oun K
y
u,
et al.
C
onc
urrenc
y
bugs
in mu
ltith
r
ead
ed soft
w
a
r
e
: mode
lin
g
and an
al
ysis
usin
g
Petir ne
ts.
Discrete E
v
ent Dyn
a
m
ic
System
s: T
h
e
o
ry an
d Ap
pl
ic
ations
. 201
3;
23(2): 15
7-1
9
5
.
[2]
Doug Lea. T
he java.util.conc
urrent s
y
n
c
hr
oniz
e
r frame
w
ork.
Scie
nce of
Co
mputer Progra
m
mi
ng
.
200
5; 58(3): 29
3-30
9.
[3]
Brad
Lo
ng, Pa
ul Stro
oper,
Lu
ke W
ildm
an. A
metho
d
for
ve
rif
y
i
n
g
conc
urr
ent Jav
a
c
o
mp
one
nts b
a
s
e
d
on a
n
an
al
ysi
s
of concurre
nc
y
fa
ilur
e
s.
Conc
urrency a
nd
Co
mputati
o
n:
Practice an
d Experi
enc
e
.
200
7; 19(3): 28
1-29
4.
[4]
Brad Lo
ng. A F
r
ame
w
ork for
Model Ch
ecki
ng Co
ncurre
nt Java Compo
n
ents.
Journa
l of Softw
are.
200
9; 4(8): 867
-874.
[5]
Yaniv E
y
ta
ni. Conc
urretn Ja
va T
e
st
Gener
ation as
a Sea
r
ch Probl
em.
Electron
ic Notes
in T
heor
etic
a
l
Co
mp
uter Scie
nce.
200
6; 144
(4): 57-72.
[6]
Pavel G Z
a
y
k
ov, Georgi Ku
zmanov. Multit
hrea
din
g
on re
dconfi
gura
b
l
e
hard
w
a
r
e: An
architectur
e
a
l
appr
oach.
Micr
oproc
essors and Microsystem
s
. 20
12; 36(
8
)
: 695-70
4.
[7]
Jonath
an A
l
dri
c
h, Emin Gun
Si
rer, Crai
g C
h
ambers, Sus
a
n
J Egger
s. C
o
mpreh
ensiv
e s
y
nc
hro
n
izati
o
n
elimi
nati
on for Java.
Scienc
e of Computer Pr
ogra
m
mi
ng
. 20
03; 47(2): 9
1
-1
20.
[8]
Seethar
ami Se
elam, Ya
nbi
n L
i
u, Parij
a
t Dub
e
, et al. Experi
ences i
n
b
u
il
di
ng a
nd sca
lin
g
an e
n
terpris
e
app
lica
i
ton
on
multicor
e s
y
s
t
ems.
Concurr
ency a
nd
Co
mp
utatio
n: Pra
c
tice an
d Exp
e
rie
n
ce
. 2
012;
24(2): 11
1-1
2
3
.
[9]
V Rafe, AT Rahmani, L Baresi
, P Spoleti
n
i. T
o
w
a
rds A
u
tomated V
e
rif
i
catio
n
of La
yered Grap
h
T
r
ansformation
Specificati
ons.
Journa
l of IET
Softw
are
. 2009
; 3(4): 276-29
1
.
[10] J
y
otirm
o
y
V,
Dshmuk
h E,
Alle
n Emerso
n
,
Sriram Sank
aran
ara
y
a
n
a
n
. S
y
m
bol
ic mo
dul
ar d
ead
lock
analy
sis.
Auto
mate
d Softw
are Engi
ne
erin
g
. 2011; 1
8
(3): 3
25-3
62.
[11]
Mariagr
azi
a
D
o
toli, Mar
i
a Pi
a F
anti. De
ad
l
o
ck Detecti
on
and Av
oi
danc
e Strategi
es f
o
r Automate
d
Storage an
d Retriev
a
l
S
y
st
ems.
IEEE
Transacti
on on Systems,
MA
N, and
Cyb
e
rnetics-Part C:
Appl
icatio
ns an
d Revi
ew
s
. 2007; 37(4): 5
41-
552.
Evaluation Warning : The document was created with Spire.PDF for Python.