9
งาน
Java Core, ระดับ, บทเรียน
Synchronized notes
1. The Note class will be used by threads. So be sure that attempts to access the notes list lock notes, not this
2. Calls to System.out.println must not be synchronized, i.e. must not be in the synchronized block
5
งาน
Java Core, ระดับ, บทเรียน
Synchronized notes: part 2
The Note class will be used by threads. So be sure to synchronize all methods.
9
งาน
Java Core, ระดับ, บทเรียน
Time in the garden
1. Create a public void addFruit(int index, String fruit) method that adds the fruit parameter to the fruits list at position index.
2. Create a public void removeFruit(int index) method that removes the element at position index from fruits.
3. Create a public void addVegetable(int index, String ve
9
งาน
Java Core, ระดับ, บทเรียน
Synchronized president
We meet the singleton pattern again in synchronization in a static block.
Create a synchronized block inside a static block inside the OurPresident class.
Inside the synchronized block, initialize president.
5
งาน
Java Core, ระดับ, บทเรียน
IMF
Singleton pattern: synchronization in a method.
The IMF class is the International Monetary Fund.
Create a synchronized block inside the getFund method.
Inside the synchronized block, initialize imf so that the getFund method always returns the same object.