CodeGym /Courses /Java Core /Tasks about interrupt

Tasks about interrupt

Java Core
Level 6 , Lesson 10
Available

"Hello, Amigo!"

9
Task
Java Core, level 6, lesson 10
Locked
Counting seconds
1. Write an implementation for the run method in the Stopwatch thread. 2. The Stopwatch class must count the number of seconds that have passed from the creation of the thread until a string is entered. 3. Display the number of seconds.
18
Task
Java Core, level 6, lesson 10
Locked
Countdown at the races
1. Figure out what the program does. 2. Implement the run method so that each second the count is displayed, separated by spaces and starting from numSeconds down to 1, and then "Go!" (see the examples). 3. If the thread runs for 3.5 seconds or more, interrupt it using the interrupt method and wit
4
Task
Java Core, level 6, lesson 10
Locked
Another interruption
Create a TestThread. In the main method, create a thread, run it, and then interrupt it using the interrupt() method.
9
Task
Java Core, level 6, lesson 10
Locked
No interrupt, no dice?
Figure out how the program works. Make it so that the ourInterrupt method allows the TestThread to terminate itself. Don't use the interrupt method.
9
Task
Java Core, level 6, lesson 10
Locked
One for all, all for one
1. Figure out how the program works. 1.1. Note that the Water object is the same for all the threads. 2. Implement the ourInterrupt() method so that it interrupts all threads in the threads list. 3. Correct the values ​​of the variables in the run() method: 3.1. isCurrentThreadInterrupted must be the s
Comments (30)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
vhunjek Level 33, Varazdin, Croatia
11 February 2022
Countdown at the races This is not accepted as solution try { for (int i = numSeconds; i > 0; i--) { System.out.print(i + " "); Thread.sleep(1000); } System.out.print("Go!"); } catch (InterruptedException e) { System.out.print("Interrupted!"); }
vhunjek Level 33, Varazdin, Croatia
12 February 2022
Decreasing number of seconds in the loop did the job.
Shilpa nori Level 34, Rochester, United States
31 January 2021
My nightmare: "Figure out what the code does". lol
Oliver Heintz Level 18, Mustang, United States
31 January 2021
I think I much prefer to write my own code, rather than modifying existing code. Especially when I am presented something with no context and told to "figure out what this does". Like... how about telling me what it's SUPPOSED to do.
remote87 Level 18, Sofia, Bulgaria
4 March 2021
I agree, but I assume that as a future developer, you will have to stare at some other people's code and figure out, what it does and modify it if needed, much more often than writing your own code, so I think this is a great exercise and training for the mind :)
Oliver Heintz Level 18, Mustang, United States
4 March 2021
Yeah, I get that. I don't mind looking at other peoples' code and figuring out how it's doing what it's doing. My issue is not even knowing what it's supposed to do. I guess that likely happens a lot, too, where you have massive programs with hundreds, if not thousands, of methods, and you come across something in it that you're not sure what it's supposed to be doing or what purpose it serves, but you for some reason know that it's not doing it's job correctly... I guess. Does that happen?
remote87 Level 18, Sofia, Bulgaria
4 March 2021
Honestly? I personally, have no idea, Oliver! :) Maybe 5 months ago I have only heard about a programming language with the name Java.
Steve Level 22, Carrollton, United States
2 April 2021
Yes. It can depend the way your company is organized and the role you play on your development team. You may be on a team that works on "Warranty" issues, where all the work is fixing bugs introduced by others, or you may be on a new feature development team, where you're writing new code and only fixing items that are found during internal testing. In the latter case, you might have to fix issues introduced by others if the original developer moves to another team or is otherwise unavailable to work on it. Sometimes that person does have time to share the intention of the code, and sometimes you're just walking into it blind.
Attila Level 25
7 April 2020
#5 Use the official version.
Nyerges Ferenc Level 31, Bükkábrány, Hungary
10 February 2020
Awesome tasks, this topic was a grey area to me till now
Robert Constantinescu Level 25, Bucharest, Romania
22 November 2019
Great job being one of the few to arrive here ! Good luck further ! I was lvl 19 when i wrote this. What level am i know?
Dexter Ellis III Level 24, Boston, United States
14 December 2019
22!
jamylam Level 26, Nairobi, Kenya
24 January 2020
25
Sanjay Chauhan Level 28, Delhi, India
11 March 2020
I am on Level 17.
Manish Sinha Level 1, london, United Kingdom
16 April 2020
still 25
Jakub M Level 32, Ostrava, Czech Republic
13 July 2020
Now or know? :D Still 25 - congratulations, good achievement!
11 August 2020
still 19 :D
Andrei Level 41
16 December 2020
I am 17. You are 25.
Vitalina Level 20, Poland
25 December 2020
25!
Maciej Florys Level 17
5 June 2021
Stuck at 25th. Take notes guys, 25th must be a nightmare!
msantagiulianab Level 26, London, United Kingdom
6 October 2019
Can anyone please recommend a good source to study multithreading in java? (website or book)
Seb Level 41, Crefeld, Germany
3 February 2020
Quest 3 on this very website... ;-)
hosniaro Level 27, Heiloo, Israel
4 April 2021
Free course at Udemy https://www.udemy.com/course/java-multithreading/learn/lecture/107238?start=165#overview
Juanf Level 26
24 September 2019
Well..., I'd say that in "No interrupt, no dice?" they should clarify more in requirements how much or how less and where it is possible to change the code..., otherwise you can break your head looking for a walkaround while it's easier...
Almaz Temirkanov Level 24, Bishkek, Kyrgyzstan
11 September 2019
#4 use isCancel
Almaz Temirkanov Level 24, Bishkek, Kyrgyzstan
11 September 2019
#2 Attention -> volatile int