#186 Repeat Annotation for Repeated Exercise Execution
Create your own Repeat annotation with an integer parameter. Extend the ThreadPoolExecutor class and override the execute method as follows:
if a Runnable instance has the Repeat annotation, its run method must execute several times, with the number of executions specified by the parameter in Repeat.
That is, after writing the following class:
@Repeat(3)
class MyRunnable implements Runnable{
@Override
public void run() {
System.out.println("Hello!");
}
}
and using it:
public static void main(String[] strings) {
CustomThreadPoolExecutor customThreadPoolExecutor =
new CustomThreadPoolExecutor(10);
customThreadPoolExecutor.execute(new MyRunnable());
}
we should see:
Hello!
Hello!
Hello!
Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor