Created
January 16, 2020 08:15
-
-
Save ereshzealous/4bab00a981c528cef779de597dca6c8d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.minikube.sample.rest.controller; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.context.annotation.Scope; | |
import org.springframework.stereotype.Component; | |
import java.util.concurrent.atomic.AtomicInteger; | |
/** | |
* Created By Gorantla, Eresh on 13/Jan/2020 | |
**/ | |
@Component | |
@Scope("singleton") | |
public class SingletonBean { | |
private Logger logger = LoggerFactory.getLogger(this.getClass()); | |
private static final AtomicInteger instanceCounter = new AtomicInteger(0); | |
public SingletonBean() { | |
logger.info("Creating Singleton instance ............"); | |
instanceCounter.incrementAndGet(); | |
} | |
static int getInstanceCounter() { | |
return instanceCounter.get(); | |
} | |
public void printData() { | |
logger.info("Singleton Bean counter => {}", getInstanceCounter()); | |
logger.info("Singleton Bean => {}", this.hashCode()); | |
logger.info("................................................."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment