Đang chuẩn bị liên kết để tải về tài liệu:
Thinking in Java 4th Edition phần 9

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

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 www.simpopdf.com 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 java.lang.ThreadLocal class as seen here concurrency ThreadLocalVariableHolder.java Automatically giving each thread its own storage. import java.util.concurrent. import java.util. class Accessor implements Runnable private final int id public Accessor int idn id idn public void run while Thread.currentThread .isInterrupted ThreadLocalVariableHolder.increment System.out.println this Thread.yield public String toString return id ThreadLocalVariableHolder.get public class ThreadLocalVariableHolder private static ThreadLocal Integer value new ThreadLocal Integer private Random rand new Random 47 protected synchronized Integer initialValue return rand.nextInt 10000 . public static void increment value.set value.get 1 public static int get return value.get public static void main String args throws Exception ExecutorService exec Executors.newCachedThreadPool for int i 0 i 5 i exec.execute new Accessor i TimeUnit.SECONDS.sleep 3 Run for a while exec.shutdownNow All .

crossorigin="anonymous">
Đã 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.