250+ TOP MCQs on Transactions and Retrying and Answers

Java Spring Questions & Answers for entrance exams on “Transactions and Retrying”.

1. Transaction capabilities are built on top of the first class support already provided by the core Spring framework.
a) True
b) False
Answer: a
Clarification: Where relevant, Spring Batch surfaces the configuration so that you can control it.

2. Spring core framework provides first-class support for transactions.
a) Transaction
b) TransactionManager
c) All of the mentioned
d) None of the mentioned
Answer: b
Clarification: You simply wire up a TransactionManager and give Spring Batch a reference, just as you would in any regular JdbcTemplate or HibernateTemplate solution.

3. The batch.xml file establishes a:-
a) BasicDataSource
b) DataSourceTransactionManager
c) All of the mentioned
d) None of the mentioned
Answer: c
Clarification: The TransactionManager and BasicDataSource were then wired to the JobRepository, which was in turn wired to the JobLauncher, which you used to launch all jobs thus far.

4. Spring Batch will, by default, try to pluck the:-
a) PlatformTransactionManager
b) transactionManager
c) All of the mentioned
d) None of the mentioned
Answer: c
Clarification: The transaction manager reference can be specified, but in your solutions, it wasn’t required because Spring Batch will, by default, try to pluck the PlatformTransactionManager named transactionManager from the context and use it.

5. Spring Batch excels in the robustness it surfaces as simple configuration options for the edge and failure cases.
a) True
b) False
Answer: a
Clarification: If a write fails on an ItemWriter, or some other exception occurs in processing, Spring Batch will rollback the transaction.

6. Element to configure this for the step:-
a) no-rollback-exception-classes
b) no-rollback-exception
c) no-rollback
d) none of the mentioned
Answer: a
Clarification: You can use the no-rollback-exception-classes element to configure this for the step. The value is a list of Exception classes that should not cause the transaction to roll back.

7. no-rollback-exception-classes element Exception classes that should not cause the transaction to roll back.

<step id = "step2">
   <tasklet>
           <chunk reader="reader" writer="writer" commit-interval="10" />
           <no-rollback-exception-classes>
           <include class="com.yourdomain.exceptions.YourBusinessException"/>
           no-rollback-exception-classes>
   tasklet>
step>

a) True
b) False
Answer: a
Clarification: You can use the no-rollback-exception-classes element to configure this for the step. The value is a list of Exception classes that should not cause the transaction to roll back.

8. You want to work with a resource that may fail when you try to read from or write to it.
a) TransactionManager
b) Transaction
c) Spring batch retry
d) All of the mentioned
Answer: c
Clarification: Use Spring Batch retry capabilities to systematically retry the read or write.

9. Some invocations will fail but may be retried with some likelihood of success in a transactional scenario.
a) True
b) False
Answer: b
Clarification: For example, an update to the database resulting in org.springframework.dao.DeadlockLoserDataAccessException might be usefully retried.

10. You can specify exception classes on which to retry the operation.

<step id = "step23">
       <tasklet transaction-manager="transactionManager">
            <chunk reader="csvFileReader" writer="jdbcItemWriter" commit-interval="10" retry-limit="3" cache-capacity="10">
           <retryable-exception-classes>
           <include class="org.springframework.dao.DeadlockLoserDataAccessException"/>
           retryable-exception-classes> 
           chunk>
       tasklet>
step>

a) True
b) False
Answer: a
Clarification: As with the rollback exceptions, you can delimit this list of exceptions with newlines or commas.

11. You can leverage Spring Batch support for retries and recovery in your own code.
a) True
b) False
Answer: a
Clarification: For example, you can have a custom ItemWriter in which retry functionality is desired or even an entire service interface for which retry support is desired.

12. The template that (much like its various other Template cousins) isolates your logic from the nuances of retries and instead enables you to write the code as though you were only going to attempt it once.
a) Retry
b) RetryTemplate
c) All of the mentioned
d) None of the mentioned
Answer: b
Clarification: Spring Batch supports these scenarios through the RetryTemplate that (much like its various other Template cousins) isolates your logic from the nuances of retries and instead enables you to write the code as though you were only going to attempt it once.

13. The RetryTemplate supports many use cases, with convenient APIs to wrap.
a) True
b) false
Answer: a
Clarification: Otherwise tedious retry/fail/recover cycles in concise, single-method invocations.

14. The RetryTemplate itself is configured in the Spring context, although it’s trivial to create in code.
a) True
b) False
Answer: a
Clarification: I declare it in the Spring context only because there is some surface area for configuration when creating the object, and I try to let Spring handle the configuration.

15. One of the more useful settings for the RetryTemplate is the :-
a) BackOff
b) Back
c) BackOffPolicy
d) All of the mentioned
Answer: c
Clarification: BackOffPolicy dictates how long the RetryTemplate should back off between retries.


To practice all areas of Java Spring for entrance exams,

Leave a Reply

Your email address will not be published. Required fields are marked *