Junior — Middle
Have you used batch data processing techniques in Java?
sobes.tech AI
Answer from AI
Yes, I have used batch processing techniques in Java when it is necessary to efficiently handle large volumes of data or perform database operations.
For example, when working with JDBC, you can collect multiple SQL queries into a batch and send them with a single call, which reduces network calls and improves performance:
Connection conn = dataSource.getConnection();
PreparedStatement ps = conn.prepareStatement("INSERT INTO users(name, email) VALUES (?, ?)");
for (User user : users) {
ps.setString(1, user.getName());
ps.setString(2, user.getEmail());
ps.addBatch();
}
int[] results = ps.executeBatch();
ps.close();
conn.close();
Batch processing is also used in data streams (for example, with Stream API), where data is processed in blocks to optimize resources.