CodeGym /Courses /Java Core /Practice with threads | Level 6

Practice with threads | Level 6

Java Core
Level 6 , Lesson 3
Available

"Hello, Amigo!"

4
Task
Java Core, level 6, lesson 3
Locked
My first thread
The grand moment arrived at last! Brace yourself: you have to create your very own thread. Create a public static TestThread class, a thread with the Runnable interface.
4
Task
Java Core, level 6, lesson 3
Locked
My second thread
Let's continue to unravel threads. This time, we need to create a public static TestThread class that inherits the Thread class. Then we'll create a static block inside TestThread, which will display "This is the static block inside TestThread". And the run method should display "This is the run method".
9
Task
Java Core, level 6, lesson 3
Locked
A list and some threads
Let's multiply threads again and again. In the main method, add five threads to the static list. Each thread must be a new Thread object that works with its own SpecialThread object. The SpecialThread class's run method should display "This is the run method inside SpecialThread".
4
Task
Java Core, level 6, lesson 3
Locked
Displaying a stack trace
Do you still remember about the stack trace and the fact that the currently running method is at the top of the stack? Let's recall this by completing a task: you need to create a "task" (a public static class called SpecialThread that implements the Runnable interface). SpecialThread should display its own stack trace.
9
Task
Java Core, level 6, lesson 3
Locked
Let's talk music
Even robotic programmers yearn for art! Today we're talking about bowed string instruments. We have a Violin class. You need to change it to make it a task for a thread. To do this, use the MusicalInstrument interface. And then you can "play" it and display how long you've been playing.
Comments (18)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Evgeniia Shabaeva Level 37, Budapest, Hungary
26 July 2024
The theory scared me at first, but the tasks appeared to be simple and helpful. I think I understood the topic better by doing them.
vhunjek Level 33, Varazdin, Croatia
8 February 2022
"A list and some threads" task doesn't accept this as solution: for (int i = 0; i < list.size(); i++) { list.add(new Thread(new SpecialThread())); }
aijo Level 30, Germany, Germany
10 February 2022
list size is changing with each iteration, as you're adding new elements to it, perhaps that's why? I imagine the following code should be accepted:

for (int i = 0; i < 5; i++) {
            list.add(new Thread(new SpecialThread()));
        }
vhunjek Level 33, Varazdin, Croatia
12 February 2022
Yeah, you are right, have underestimated the task and quickly skimmed over, somehow left List out of ArrayList.
Manish Sinha Level 26, london, United Kingdom
14 April 2020
have done the tasks. Thanks Codegym. I need more clarity when to use thread.Hopefully , would learn in coming lessons. Pretty excited.
MaGaby2280 Level 41, Guatemala City, Guatemala
20 January 2020
Great tasks to understand multithreading better and remember old concepts like stacktrace ;o)
Joseph Level 22, United States
12 October 2019
First time I've seen the keyword "volatile". I knew when I started getting into multi-threading things would get interesting.
KIN SOCHEAT Level 34, Phnom Penh, Cambogia
9 September 2019
Thanks
Almaz Temirkanov Level 24, Bishkek, Kyrgyzstan
6 September 2019
#5 long start= startPlaying().getTime(); and write end time sout - "Played for " + (end-start) + " ms
Almaz Temirkanov Level 24, Bishkek, Kyrgyzstan
5 September 2019
#3 loop for 1 to 5 and add threads list.add(new Thread(new SpecialThread()));
Devonte A Level 18, Rubery, United Kingdom
15 July 2020
Please dont give answers..
23 August 2019
pretty interesting how threads have worked up to these tasks but don't know how they can be applied in a practical way. I hope that's about to come!
Senned Level 41, Azov, Russia
13 August 2019
In task "A list and some threads" do not start Threads, validator thinking thats incorrect.