Java Springboot Microservices FAQs

1. Is Spingboot thread-safe? 

It depends. The main factor which determines the thread-safety of a component is its scope.

In a standard servlet-based Spring web application, every new HTTP request generates a new thread. If the container creates a new bean instance just for that particular request, we can say this bean is thread-safe.

Is Spring singleton thread-safe?
The short answer is: no, it isn’t.


2. How do we implement spring security?
Dependency :


start by creating a Spring Security configuration class that extends WebSecurityConfigurerAdapter. By adding @EnableWebSecurity, we get Spring Security and MVC integration support.


3. How to cancel an order for user-specific settings at the spring level? 

3b. Multi calls between ms to ms? 

4. Tomcat Max Threads settings in Springboot application? 

Maximum number of connections that the server accepts and processes at any given time. Once the limit has been reached, the operating system may still accept connections based on the "acceptCount" property.
Maximum size of the form content in any HTTP post request.
Maximum amount of request body to swallow.
Maximum amount of worker threads.
Whether Tomcat's MBean Registry should be enabled.
Minimum amount of worker threads.
Name of the HTTP header used to override the original port value.
Maximum number of idle processors that will be retained in the cache and reused with a subsequent request. When set to -1 the cache will be unlimited with a theoretical maximum size equal to the maximum number of connections.
Header that holds the incoming protocol, usually named "X-Forwarded-Proto".
Reference :

5. Sort Employee salary using Java Streams and display salary which is greater than X amount? Java 8 - streams, lambda expression

// find employees whose salaries are above 10000>emp.getSalary() > 10000).forEach(System.out::println);

Reference :

6. When do we use java inner classes?
It is a way of logically grouping classes that are only used in one place: If a class is useful to only one other class, then it is logical to embed it in that class and keep the two together. Nesting such "helper classes" makes their package more streamlined.

Use a non-static nested class (or inner class) if you require access to an enclosing instance's non-public fields and methods. Use a static nested class if you don't require this access.

Inner classes are used to get functionality that can get an object better than method.
They can be used in the case when a set of multiple operations are required and chances of reusability are good inside the class and they will not be accessed but methods outside the outer class.
Inner classes are made to achieve multiple inheritances also.
Inner classes are used when they are useful in the class context.
They are used to separate logic inside classes.
inner class means one class which is a member of another class. There are basically four types of inner classes in java.

1) Nested Inner class

2) Method Local inner classes

3) Anonymous inner classes

4) Static nested classes

7. Spring boot - Dependency injection types? 

There are basically three types of dependency injection:
constructor injection: the dependencies are provided through a class constructor.
setter injection: the client exposes a setter method that the injector uses to inject the dependency.
interface injection: the dependency provides an injector method that will inject the dependency into any client passed to it. Clients must implement an interface that exposes a setter method that accepts the dependency.
So now its the dependency injection’s responsibility to:

  • Create the objects
  • Know which classes require those objects
  • And provide them all those objects
Reference :
8 . Mutable(Changable) Vs Immutable(Not Changable) ? 

Mutable object – You can change the states and fields after the object is created

Sting is im-mutable , Stringbuffer is mutable and Date is mutable  .

How to create a Mutable class?
To create a mutable class in Java you have to make sure the following requirements are satisfied:

  • Provide a method to modify the field values
  • Getter and Setter method

How to create an Immutable class?
A class should be declared as final so that it can’t be extended.
All the fields should be made private so that direct access is not allowed
No setter methods
Make all mutable fields final, so that they can be assigned only once.


0 comments to "Java Springboot Microservices FAQs"

Post a comment

Whoever writes Inappropriate/Vulgar comments to context, generally want to be anonymous …So I hope U r not the one like that?
For lazy logs, u can at least use Name/URL option which doesn’t even require any sign-in, The good thing is that it can accept your lovely nick name also and the URL is not mandatory too.
Thanks for your patience
~Krishna(I love "Transparency")

Popular Posts

Enter your email address:

Buffs ...


Powered by WidgetsForFree