1Z0-829 Java I/O API and Securing Applications Practice Question
A developer is designing a service that processes multiple files concurrently. To avoid resource leaks, which practice is essential?
⚠ Common exam trap
It's easy for candidates to think explicit close() calls in separate try-catch blocks are safer, but they overlook that try-with-resources handles suppression and automatic closure more reliably, especially in concurrent scenarios where resource leaks are harder to detect.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Use try-with-resources for each AutoCloseable resource
Try-with-resources guarantees that each AutoCloseable resource is closed automatically at the end of the statement, even if an exception occurs. This is essential when processing multiple files concurrently, as it prevents resource leaks without requiring explicit close() calls in finally blocks.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Ensure each thread has its own copy of the file handle
Why it's wrong here
Thread safety does not prevent resource leaks.
- ✓
Use try-with-resources for each AutoCloseable resource
Why this is correct
try-with-resources guarantees closure of each resource in the correct order, even with exceptions.
- ✗
Call close() on each stream in a separate try-catch block
Why it's wrong here
This is error-prone and can lead to leaks if an exception occurs before close.
- ✗
Use FileLock to prevent concurrent access
Why it's wrong here
FileLock prevents conflicts but does not handle resource cleanup.
Go deeper
Related to this question
About these practice questions
Courseiva writes every 1Z0-829 question from scratch — 513 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 1Z0-829 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-829 exam.