TAILIEUCHUNG - Thinking in Java 4th Edition phần 9

Vì vậy, bạn phải cẩn thận phân tích thí nghiệm của bạn và để hiểu những hạn chế của họ. Tùy thuộc vào hành vi mà bạn mong muốn, Để chạy chương trình, bạn gõ một dòng lệnh của một trong hai: Lựa chọn giữa Bộ | Simpo PDF Merge and Split Unregistered Version - http Exercise 15 1 Create a class with three methods containing critical sections that all synchronize on the same object. Create multiple tasks to demonstrate that only one of these methods can run at a time. Now modify the methods so that each one synchronizes on a different object and show that all three methods can be running at once. Exercise 16 1 Modify Exercise 15 to use explicit Lock objects. Thread local storage A second way to prevent tasks from colliding over shared resources is to eliminate the sharing of variables. Thread local storage is a mechanism that automatically creates different storage for the same variable for each different thread that uses an object. Thus if you have five threads using an object with a variable x thread local storage generates five different pieces of storage for x. Basically they allow you to associate state with a thread. The creation and management of thread local storage is taken care of by the class as seen here concurrency Automatically giving each thread its own storage. import . import . class Accessor implements Runnable private final int id public Accessor int idn id idn public void run while .isInterrupted this public String toString return id public class ThreadLocalVariableHolder private static ThreadLocal Integer value new ThreadLocal Integer private Random rand new Random 47 protected synchronized Integer initialValue return 10000 . public static void increment 1 public static int get return public static void main String args throws Exception ExecutorService exec for int i 0 i 5 i new Accessor i 3 Run for a while All .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.