Clean Code



Download 3,58 Mb.
Pdf ko'rish
bet179/384
Sana05.04.2022
Hajmi3,58 Mb.
#530298
1   ...   175   176   177   178   179   180   181   182   ...   384
Bog'liq
Clean Code

Know Your Library
Java 5 offers many improvements for concurrent development over previous versions. There
are several things to consider when writing threaded code in Java 5:
• Use the provided thread-safe collections.
• Use the executor framework for executing unrelated tasks.
• Use nonblocking solutions when possible.
• Several library classes are not thread safe.
Thread-Safe Collections
When Java was young, Doug Lea wrote the seminal book
8
Concurrent Programming in
Java
. Along with the book he developed several thread-safe collections, which later
became part of the JDK in the 
java.util.concurrent
package. The collections in that pack-
age are safe for multithreaded situations and they perform well. In fact, the
8. [Lea99].


183
Know Your Execution Models
ConcurrentHashMap
implementation performs better than 
HashMap
in nearly all situations. It
also allows for simultaneous concurrent reads and writes, and it has methods supporting
common composite operations that are otherwise not thread safe. If Java 5 is the deploy-
ment environment, start with 
ConcurrentHashMap
.
There are several other kinds of classes added to support advanced concurrency
design. Here are a few examples:
Recommendation
:
Review the classes available to you. In the case of Java, become
familiar with java.util.concurrent, java.util.concurrent.atomic, java.util.concurrent.locks.
Know Your Execution Models
There are several different ways to partition behavior in a concurrent application. To dis-
cuss them we need to understand some basic definitions.
Given these definitions, we can now discuss the various execution models used in
concurrent programming.

Download 3,58 Mb.

Do'stlaringiz bilan baham:
1   ...   175   176   177   178   179   180   181   182   ...   384




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish