anakin59490
anakin59490

Reputation: 672

Java Class Instances in Rest Application

It's maybe a stupid question for Java expert, but I need to understand.

I have a REST App with Controllers and Services. I use Java 8 and spring-boot.

When a request arrives, my service creates a new class instance, for example:

ContactDTO contactDTO = new ContactDTO();

If one day one hundred requests arrive in the same time, one hundred ContactDTO class instance will be created. And more generally in a working day, a lot of instances are created. But what happens to those instances when the service has finished his job?

I know there was Garbage Collector service in former Java versions, I don't know if it's still present in Java 8, 9, etc. I read also tuto about @Transactional Spring annotation or Singleton in order to manage database access, but I'm a little confused with this.

What is the best way to manage these instances when they are no longer in use? And what effect about App performance if they are still active?

Upvotes: 0

Views: 101

Answers (1)

ParanoiK
ParanoiK

Reputation: 41

Garbage collector will take care of this. You can read here about basics. For Java8 Parallel is default GC.

Upvotes: 1

Related Questions