1. Learn
  2. /
  3. Courses
  4. /
  5. Optimizing Code in Java

Connected

Exercise

Implementing lazy initialization

You're working on optimizing the startup time of a Java application. The team has identified that creating database connections eagerly is causing unnecessary delays. You need to implement lazy initialization, i.e., creating a connection only if there is none, for the Database class to improve startup performance.

Instructions

100 XP
  • Create a property client of type DatabaseClient.
  • Lazily connect to our database.
  • Return our database client only when connected.