Skip to content

Commit 3c5aef5

Browse files
committed
GH-1258: Change OOMHandler to JavaLangErrorHandler
Resolves #1258 Call the handler for all `Error`s on container threads. **I will do the cherry-pick; there will be conflicts**
1 parent 3879496 commit 3c5aef5

File tree

5 files changed

+18
-21
lines changed

5 files changed

+18
-21
lines changed

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/AbstractMessageListenerContainer.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public abstract class AbstractMessageListenerContainer extends RabbitAccessor
244244

245245
private boolean isBatchListener;
246246

247-
private OOMHandler oOMHandler = error -> System.exit(99);
247+
private JavaLangErrorHandler javaLangErrorHandler = error -> { };
248248

249249
private volatile boolean lazyLoad;
250250

@@ -1125,19 +1125,19 @@ public void setMicrometerEnabled(boolean micrometerEnabled) {
11251125
this.micrometerEnabled = micrometerEnabled;
11261126
}
11271127

1128-
protected OOMHandler getOOMHandler() {
1129-
return this.oOMHandler;
1128+
protected JavaLangErrorHandler getJavaLangErrorHandler() {
1129+
return this.javaLangErrorHandler;
11301130
}
11311131

11321132
/**
1133-
* Provide an OOMHandler implementation; by default, {@code System.exit(99)} is
1134-
* called.
1135-
* @param oOMHandler the handler.
1133+
* Provide a JavaLangErrorHandler implementation; by default no action is taken,
1134+
* for backwards compatibility; generally the JVM should be terminated.
1135+
* @param javaLangErrorHandler the handler.
11361136
* @since 2.2.12
11371137
*/
1138-
public void setOOMHandler(OOMHandler oOMHandler) {
1139-
Assert.notNull(oOMHandler, "'oOMHandler' cannot be null");
1140-
this.oOMHandler = oOMHandler;
1138+
public void setjavaLangErrorHandler(JavaLangErrorHandler javaLangErrorHandler) {
1139+
Assert.notNull(javaLangErrorHandler, "'javaLangErrorHandler' cannot be null");
1140+
this.javaLangErrorHandler = javaLangErrorHandler;
11411141
}
11421142

11431143
/**
@@ -1968,18 +1968,18 @@ private interface ContainerDelegate {
19681968
}
19691969

19701970
/**
1971-
* A handler for {@link OutOfMemoryError} on the container thread(s).
1971+
* A handler for {@link Error} on the container thread(s).
19721972
* @since 2.2.12
19731973
*
19741974
*/
19751975
@FunctionalInterface
1976-
public interface OOMHandler {
1976+
public interface JavaLangErrorHandler {
19771977

19781978
/**
19791979
* Handle the error; typically, the JVM will be terminated.
19801980
* @param error the error.
19811981
*/
1982-
void handle(OutOfMemoryError error);
1982+
void handle(Error error);
19831983

19841984
}
19851985

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/DirectMessageListenerContainer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,8 +1085,8 @@ private void callExecuteListener(Object data, long deliveryTag) {
10851085
}
10861086
}
10871087
}
1088-
catch (OutOfMemoryError e) { // NOSONAR
1089-
getOOMHandler().handle(e);
1088+
catch (Error e) { // NOSONAR
1089+
getJavaLangErrorHandler().handle(e);
10901090
throw e;
10911091
}
10921092
}

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/SimpleMessageListenerContainer.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,12 +1264,9 @@ public void run() { // NOSONAR - line count
12641264
}
12651265
}
12661266
catch (Error e) { //NOSONAR
1267-
// ok to catch Error - we're aborting so will stop
12681267
logger.error("Consumer thread error, thread abort.", e);
1269-
if (e instanceof OutOfMemoryError) { // NOSONAR
1270-
getOOMHandler().handle((OutOfMemoryError) e);
1271-
}
12721268
publishConsumerFailedEvent("Consumer threw an Error", true, e);
1269+
getJavaLangErrorHandler().handle(e);
12731270
aborted = true;
12741271
}
12751272
catch (Throwable t) { //NOSONAR

src/reference/asciidoc/amqp.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5430,10 +5430,10 @@ Default is a `SimpleAsyncTaskExecutor`, using internally managed threads.
54305430
a| image::images/tickmark.png[]
54315431
a| image::images/tickmark.png[]
54325432

5433-
| oOMHandler
5433+
| javaLangErrorHandler
54345434
(N/A)
54355435

5436-
| An `AbstractMessageListenerContainer.OOMHandler` implementation that is called when a container thread catches an `OutOfMemoryException`.
5436+
| An `AbstractMessageListenerContainer.JavaLangErrorHandler` implementation that is called when a container thread catches an `Error`.
54375437
The default implementation does nothing, for backwards compatibility.
54385438
Normally, the JVM should be terminated; this will be the default action in a future release.
54395439

src/reference/asciidoc/whats-new.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ See <<exception-handling>> for more information.
3535
Listener performance can now be monitored using Micrometer `Timer` s.
3636
See <<micrometer>> for more information.
3737

38-
You can now configure an `OOMHandler` (out of memory handler); the default implementation does nothing, for backwards compatibility.
38+
You can now configure an `JavaLangErrorHandler`; the default implementation does nothing, for backwards compatibility.
3939
Normally, the JVM should be terminated; this will be the default action in a future release.
4040
See <<containerAttributes>> for more information.
4141

0 commit comments

Comments
 (0)