Roman Nikitchenko
Roman Nikitchenko

Reputation: 13046

How to signal about 'retry exceeded' during concurrent write in Java through Exception?

I have Java class which has intention to support distributed container. During the 'change publication' there is always possibility of conflict so there is retry implemented. But there is always probability of number of re-tries exceeded.

Is there any 'standard' or recommended way to signal this situation in Java with exception? java.io.IOException (what I'm using now) looks like non-relevant as there is no actual IO error, it is just logic conflict around concurrency. Any grounded recommendation of something more specific?

Upvotes: 1

Views: 586

Answers (1)

Zim-Zam O'Pootertoot
Zim-Zam O'Pootertoot

Reputation: 18148

For the application I'm working on we keep a List of the exceptions that have resulted in job retries, then when the job terminates we log (via SLF4J) a serialized JobSummary object that includes the list of exceptions and their stack traces (gained via ExceptionUtils) as well as whether the number of retries was exceeded (i.e. whether the job ultimately succeeded or failed). Had we opted for throwing an exception instead of logging then we'd have had put the JobSummary data in a subclass of RumTimeException or Exception (as suggested by @Gábor Bakos in the comments). In general, there's nothing wrong with rolling your own exception class(es) if doing so provides better debugging/logging/etc data.

Upvotes: 1

Related Questions