Why is the task not accepted?
All these constructors were produced by IntelliJ IDEA(Alt+Insert), I just added the logic to the corresponding two constructors.
Validation result:
Error in com/codegym/task/task28/task2805/MyThread.java on line 58
no suitable constructor found for Thread(java.lang.ThreadGroup,java.lang.Runnable,java.lang.String,long,boolean)
constructor java.lang.Thread.Thread() is not applicable
(actual and formal argument lists differ in length)
constructor java.lang.Thread.Thread(java.lang.Runnable) is not applicable
(actual and formal argument lists differ in length)
constructor java.lang.Thread.Thread(java.lang.Runnable,java.security.AccessControlContext) is not applicable
(actual and formal argument lists differ in length)
constructor java.lang.Thread.Thread(java.lang.ThreadGroup,java.lang.Runnable) is not applicable
(actual and formal argument lists differ in length)
constructor java.lang.Thread.Thread(java.lang.String) is not applicable
(actual and formal argument lists differ in length)
constructor java.lang.Thread.Thread(java.lang.ThreadGroup,java.lang.String) is not applicable
(actual and formal argument lists differ in length)
constructor java.lang.Thread.Thread(java.lang.Runnable,java.lang.String) is not applicable
(actual and formal argument lists differ in length)
constructor java.lang.Thread.Thread(java.lang.ThreadGroup,java.lang.Runnable,java.lang.String) is not applicable
(actual and formal argument lists differ in length)
constructor java.lang.Thread.Thread(java.lang.ThreadGroup,java.lang.Runnable,java.lang.String,long) is not applicable
(actual and formal argument lists differ in length)
package com.codegym.task.task28.task2805;
/*
Thread priorities
*/
public class Solution {
public static void main(String[] args) {
for (int i = 0; i < 12; i++) {
System.out.print(new MyThread().getPriority() + " ");
}
// Output
// 1 2 3 4 5 6 7 8 9 10 1 2
System.out.println();
ThreadGroup group = new ThreadGroup("someName");
group.setMaxPriority(7);
for (int i = 0; i < 12; i++) {
System.out.print(new MyThread(group, "name" + i).getPriority() + " ");
}
// Output
// 3 4 5 6 7 7 7 7 1 2 3 4
}
}
/* CONSOLE OUTPUT:
1 2 3 4 5 6 7 8 9 10 1 2
3 4 5 6 7 7 7 7 1 2 3 4
Process finished with exit code 0
-----------------------------------------------------------------------------------
Thread priorities
In a separate file, create a class called MyThread that inherits Thread. MyThread must:
1. Be able to be created using any of the superclass's constructors (Alt+Insert).
2. Thread priorities must be set using a loop—from the minimum to the maximum value.
3. If the thread has a thread group (ThreadGroup), then the thread's priority can't be
greater than its thread group's maximum priority.
**
В отдельном файле создайте класс MyThread, который наследует Thread. MyThread должен:
1. Возможность создания с помощью любого из конструкторов суперкласса (Alt+Insert).
2. Приоритеты потоков необходимо задавать с помощью цикла — от минимального до
максимального значения.
3. Если у потока есть группа потоков (ThreadGroup), то приоритет потока не может быть
больше максимального приоритета его группы потоков.
Requirements:
1. Create a MyThread class in a separate file. Make it inherit Thread.
2. The MyThread class must have constructors similar to the superclass's constructors.
3. The priority of the MyThread objects should be set using a loop, from MIN_PRIORITY
to MAX_PRIORITY.
4. If a MyThread object has a ThreadGroup, then the MyThread's priority must not be
greater than the ThreadGroup's maximum priority.
*/