Questions tagged [predestroy]
11 questions
35
votes
2 answers
Do Spring prototype beans need to be destroyed manually?
I noticed that the @PreDestroy hooks of my prototype scoped Spring beans were not getting executed.
I have since read here that this is actually by design. The Spring container will destroy singleton beans but will not destroy prototype beans. It…

IqbalHamid
- 2,324
- 1
- 18
- 24
3
votes
2 answers
Is @PreDestroy method call granted if we get an Exception in @PostConstract
I have SpringBoot application which is load some configuration and runs a longtime processing in method annotated with @PostConstract. There are some resources which should be released if application completed successfully or with an Error.
The…

Alexey Usharovski
- 1,404
- 13
- 31
1
vote
1 answer
@PreDestroy not invoked in JAX-RS resource, how do I close/release resources?
I have a java class annotated with the jakarta.ws.rs-api annotations, which is a rest resource class. I have created an executor service as part of the resource class (which contains methods with annotations like @GET, @PUT, etc.), and am looking…

Shaik Zakir Hussain
- 302
- 1
- 12
1
vote
1 answer
JEE: How to intercept a @PostCostruct method?
I have a bean having:
void initialize() method annotated with @PostConstruct.
void release() method annotated with @PreDestroy.
Some other methods.
In addition that bean has a @Interceptors annotation defining some interceptors.
One of those…

Grizzly
- 45
- 9
1
vote
1 answer
Spring boot clean up on sigkill
I am running a SpringBoot Application. I have added some cleanup action using @PreDestroy annotation. When I terminate the process using SIGTERM that is kill ${PID} of tomcat, it performs all the cleanup tasks by calling method marked with…

PUNEET AGARWAL
- 181
- 1
- 1
- 8
1
vote
2 answers
Shutdown @Bean ExecutorService using @PreDestroy
I have a Spring @Configuration class as follows:
@Configuration
public class ExecutorServiceConfiguration {
@Bean
public BlockingQueue queue() {
return ArrayBlockingQueue<>(1000);
}
@Bean
public…

zenn1337
- 481
- 1
- 5
- 25
1
vote
2 answers
How to call @PreDestroy for a bean declared with @Bean annotation
I have a bean declared with annotation @Bean
@Bean
public Set beans() {
Set containerSet = new HashSet();
return containerSet;
}
I have…

hars
- 127
- 4
- 17
0
votes
1 answer
Kafka manual acknowledge before Spring Boot shutdown
So the question is simple, but I cannot find an answer for quite a while now.
I have manual acknowledgement for my Kafka consumer, and before the application is shutdown I would like to execute some code and then acknowledge to Kafka. So for this I…

Zim8662
- 331
- 2
- 6
0
votes
1 answer
Why PreDestroy method doesn't work
I have a basic spring project with simple configuration. This is bean
public class GreetingServiceImpl implements GreetingService {
private final Log log = LogFactory.getLog(getClass());
@Override
public String hello() {
return…

Kirill
- 1,540
- 4
- 18
- 41
0
votes
0 answers
@PreDestroy is sometimes called once directly after @PostConstruct, sometimes called twice when triggering GET again
i am currently faced with strange problems with @PreDestroy methods in Mojarra 2.2.14: The behaviour seems to be some kind of undefined. sometimes it is called one time directly after @PostConstruct, sometimes it is called twice when triggering the…

Steve
- 384
- 1
- 7
- 17
-1
votes
2 answers
Spring issue with @PostConstruct and @PreDestroy
I have a Spring application that I am trying to test with EmbededRedis. So I created a component like below to Initialize and kill redis after test.
@Component
public class EmbededRedis {
@Value("${spring.redis.port}")
private int redisPort;
…

Anand Vaidya
- 1,374
- 11
- 26