mirror of
https://github.com/keycloak/keycloak.git
synced 2026-01-10 15:32:05 -03:30
Don't keep an old session to avoid a stable objects and a memory leak
Closes #43761 Signed-off-by: Alexander Schwartz <alexander.schwartz@ibm.com>
This commit is contained in:
parent
15fe032e8d
commit
6a4e4abf30
@ -47,12 +47,7 @@ public class BasicTimerProvider implements TimerProvider {
|
||||
|
||||
@Override
|
||||
public void schedule(final Runnable runnable, final long intervalMillis, String taskName) {
|
||||
TimerTask task = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
runnable.run();
|
||||
}
|
||||
};
|
||||
TimerTask task = new BasicTimerTask(runnable);
|
||||
|
||||
TimerTaskContextImpl taskContext = new TimerTaskContextImpl(runnable, task, intervalMillis);
|
||||
TimerTaskContextImpl existingTask = factory.putTask(taskName, taskContext);
|
||||
@ -87,4 +82,20 @@ public class BasicTimerProvider implements TimerProvider {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Using a private static class avoids keeping a reference to {@link BasicTimerProvider} which then fails to be garbage collected,
|
||||
* including its reference to {@link KeycloakSession}.
|
||||
*/
|
||||
private static class BasicTimerTask extends TimerTask {
|
||||
private final Runnable runnable;
|
||||
|
||||
public BasicTimerTask(Runnable runnable) {
|
||||
this.runnable = runnable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user