"Này, quân nhân!"
"Chúc một ngày tốt lành, thuyền trưởng!"
"Tôi có một tin tuyệt vời dành cho bạn. Đây là một số bài tập để củng cố kỹ năng của bạn. Hãy thực hiện chúng hàng ngày và kỹ năng của bạn sẽ phát triển với tốc độ chóng mặt. Chúng được tạo riêng cho IntelliJ IDEA."
"Những bài tập trước đó là dành cho tân binh. Tôi đã thêm một số bài tập bổ sung nâng cao hơn cho những người già. Chỉ dành cho những người kỳ cựu."
4
Nhiệm vụ
Java Core, mức độ, bài học
Thread.currentThread always returns the current thread
1. In the printMsg method, assign the current thread to the variable t.
2. In the printMsg method, add a delay of 1 millisecond after all the actions.
4
Nhiệm vụ
Java Core, mức độ, bài học
Consecutive threads
1. In the run method, add a delay of 10 milliseconds after all the actions. Display "Thread interrupted" if the thread is interrupted.
2. Make all the threads run sequentially: first, for thread 1, count down from COUNT to 1; then for thread 2 - from COUNT to 1, etc.
Example:
#1: 4
#1: 3
...
#1: 1
#
18
Nhiệm vụ
Java Core, mức độ, bài học
Creating threads recursively
1. Change the GenerateThread class to make it a thread.
2. Create a GenerateThread constructor, which must:
2.1. Call the superclass's constructor, passing the created thread's number as a String. Use createdThreadCount.
2.2. Start the current thread.
2.3. The thread numbers must start with 1.
3. O
4
Nhiệm vụ
Java Core, mức độ, bài học
Consecutive threads
1. Figure out what the program does.
2. Make the program first display the result of the thread, and when the thread has finished then the main method continues.
3. Example output:
inside MyThread 0
inside MyThread 1
...
inside MyThread 9
inside main 0
inside main 1
...
inside main 9
4
Nhiệm vụ
Java Core, mức độ, bài học
Deadlock
1. Figure out how the program works.
2. Without changing the T1 and T2 classes, make it so their threads finish (not necessarily successfully).
3. Don't use the sleep method.
9
Nhiệm vụ
Java Core, mức độ, bài học
Following a pattern
Figure out how the program works.
Similar to CountdownRunnable, create a CountUpRunnable thread that displays values in the counting order: from 1 to number.
18
Nhiệm vụ
Java Core, mức độ, bài học
Shall we play?
Three people play the game. Each player (Gamer) is characterized by two parameters: last name (name) and the actions-per-second (rating).
Display the actions taken and determine the winner and the losers.
Let's begin...
1. Figure out what the program does.
1.1. List actions stores the sequen
18
Nhiệm vụ
Java Core, mức độ, bài học
The early bird gets the worm
1. Figure out what the program does.
1.1. Each thread should read lines from the console. Use the existing static BufferedReader reader.
1.2. Use AtomicInteger readStringCount to calculate how many lines all the threads have read from the console.
2. Implement the run method:
2.1. As long as a thr
9
Nhiệm vụ
Java Core, mức độ, bài học
Take your turn!
1. In the Solution class, create a public static Read3Strings class that inherits Thread.
2. In the run method, read three lines from the console.
3. Three lines should be read in succession on one thread and combined into one space-delimited string.
4. In the main method, display the result for eac
18
Nhiệm vụ
Java Core, mức độ, bài học
Sequential file output
1. Figure out what the program does.
2. In a static block, read 2 filenames: firstFileName and secondFileName.
3. Inside the Solution class, create a public static ReadFileThread class that implements the
ReadFileInterface interface (Think about what is more appropriate: Thread or Runnable).
3.1. Th
18
Nhiệm vụ
Java Core, mức độ, bài học
Factory method pattern
1. Take a careful look at the classes you have.
2. In separate files in the common package, create JpgReader, PngReader, and BmpReader classes that implement the ImageReader interface.
3. In a separate file in the main package, create the ImageReaderFactory class with one method.
3.1. Think about wh
18
Nhiệm vụ
Java Core, mức độ, bài học
Clew
1. Create 5 different threads that differ from Thread:
1.1. Thread 1 must run indefinitely;
1.2. Thread 2 should display "InterruptedException" when an InterruptedException occurs;
1.3. Thread 3 should display "Hurray" every half second";
1.4. Thread 4 must implement the Message interface. When the
18
Nhiệm vụ
Java Core, mức độ, bài học
Debug everything under the sun
Figure out what the program does.
Read about UncaughtExceptionHandler - it's important.
Take another careful look at the program.
Figure out why our OurUncaughtExceptionHandler doesn't work (use the debugger).
Fix the bug, i.e. everything should work. :)
Expected result in no particular order:
Thre