Which method is used to submit a task for execution to the ExecutorService and returns a Future object?
- addTaskToExecutor(Runnable task)
- execute(Runnable task)
- startTask(Callable
task) - submit(Runnable task)
The submit(Runnable task) method of the ExecutorService interface is used to submit a task for execution and returns a Future object. This Future can be used to monitor the progress and retrieve the result of the task asynchronously. The other options are not correct methods for submitting tasks to an ExecutorService.
Loading...
Related Quiz
- Which interface or class should a class use or extend to create a new thread in Java?
- Consider a scenario where you have a class representing a "User" with a field "password". How would you ensure that the password field is securely encapsulated and cannot be directly accessed or modified without proper validation?
- How does the use of synchronized methods or blocks affect the performance of a Java application and why?
- What is the worst-case time complexity of Linear Search?
- What is the major drawback of Linear Search compared to other searching algorithms?