简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM