CodeGym /Courses /Java Core /Synchronized! The practical version

Synchronized! The practical version

Java Core
Level 7 , Lesson 4
Available

"Hello, Amigo!"

9
Task
Java Core, level 7, lesson 4
Locked
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
Task
Java Core, level 7, lesson 4
Locked
Synchronized notes: part 2
The Note class will be used by threads. So be sure to synchronize all methods.
9
Task
Java Core, level 7, lesson 4
Locked
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
Task
Java Core, level 7, lesson 4
Locked
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
Task
Java Core, level 7, lesson 4
Locked
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.
Comments (24)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Ozoda Izzatillaeva Level 27, Uzbekistan
27 April 2023
am I the only one who's not doing these on IntelliJ?
Dmytro Panshyn Level 25, Poland, Poland
6 November 2023
Hi, why you don't use Intellij?) It is more convenient.
Tasmoda Level 28, Midrand, South Africa
14 July 2022
Low on Dark matter? Worry not, we got you😂. Now you can buy 2 Dark matters for the price of 2! Hurry. Whilst stock lasts!
Coboliste Level 46, Casablanca, Morocco
11 July 2022
This solution has been validated ! and considered better than 60% other students !!!! static { president = new OurPresident(); synchronized (president) { } }
Jurij Thmsn Level 29, Flensburg, Germany
27 March 2021
Can someone explain why in "Synchronized notes" we can't use synchronize(this) ?
Juanf Level 2
23 September 2021
the "lock" (mutex) is a property of an object, so "this" doesn't refer to a block or code, but to the object that owns that block of code when executing. "Notes" is an object (List<>) so you want to synchronize only that object, not the whole Note object that owns "notes" (if you use "this").
Oliver Heintz Level 18, Mustang, United States
12 February 2021
****.class Was this even MENTIONED somewhere? Were we supposed to know to Google this?
Jurij Thmsn Level 29, Flensburg, Germany
27 March 2021
It was mentioned in one of the examples. Didn't get it either. Still don't know what it really means...
Gellert Varga Level 23, Szekesfehervar, Hungary
9 May 2021
I share what i managed to find out from others: synchronized (ClassName.class) : this notation represents the class-level lock instead of the object-level (this). When a class-level lock takes effect, it results in: - locks all synchronized static methods, and - locks all synchronized code blocks marked by ClassName.class. When a thread enters a synchronized block/method, it also locks all other blocks/methods that are synchronized with the same type.
Brad Reed Level 19, Hartford, United States
2 August 2020
Raise your hand if you failed an easy one cuz you didn't read....that would be me....
MaGaby2280 Level 41, Guatemala City, Guatemala
3 February 2020
Great tasks to start practics on synchronization!!!
Trevor Level 23, Phoenix, United States
20 January 2020
Please let us press the escape key to close out the popup modals. It's a pretty basic feature to have in any web app.
Almaz Temirkanov Level 24, Bishkek, Kyrgyzstan
17 September 2019
#5 (imf == null)
28 August 2019
only 267 users have completed the last task up to this point in time... encouraging!
Iasu Level 18, Norway
5 October 2019
How can you see the stats?
7 October 2019
Every time you verify a task the counter shows up ;)
Robert Constantinescu Level 25, Bucharest, Romania
26 November 2019
but only if you complete in IntelliJ
Sela Level 20, Poland
30 July 2020
664 by now
Lawson Level 29, Lagos, Nigeria
31 August 2020
it doesnt show in mine..
Sansho Level 19, Bordeaux, France
11 June 2021
1027 by now
aijo Level 30, Germany, Germany
13 February 2022
1143 now