#186 Repeat Annotation for Repeated Exercise Execution

Companies:
Digitalleague
Themes:
JavaConcurrencyCode Review

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

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in