Hi Friends,
In this post, I'm sharing interview questions answers asked in IBM @ experience level of 13 years.
Question 1:
How locking mechanism is implemented by JVM?
Answer:
The implementation of locking mechanism in java is specific to the instruction set of the java platform.
For example with x86, it might use the CMPXCHG - atomic compare and exchange - at the lowest level to implement the fast path of the lock.
The CMPXCHG instruction is a compare-and-swap instruction that guarantees atomic memory access at the hardware level.
If the thread cannot acquire the lock immediately, then it could spinlock or it could perform a syscall to schedule a different thread.
Different strategies are used depending on the platform, JVM switches.
Question 2:
Which Event bus is used by Saga pattern?
Answer:
When we use event based communication, a microservice publishes an event when something notable happens such as when it updates a business entity. Other microservices subscribe to those events.
When a microservice receives an event, it can update it's own business entities which might lead to more events being published.
This publish/subscribe system is usually performed by using an implementation of an event bus.
The event bus is designed as an interface with the API needed to subscribe and unsubscribe to events and to publish events.
The implementation of this event bus can be a messaging queue like RabbitMQ or service bus like Azure service bus.
Question 3:
What is the use of Amazon EC2? What are the steps to deploy on EC2?
Answer:
Amazon EC2: Amazon Elastic Compute Cloud
It offers ability to run applications on the public cloud.
It eliminates investment for hardware. There is no need to maintain the hardware.We can use EC2 to launch as many servers as we need.
Steps to deploy on EC2:
- Launch an EC2 instance and SSH into it. Note: This instance needs to be created first on Amazon console [console.aws.amazon.com]. And we should also have certificate to connect to EC2 instance.
- Install Node on EC2 instance, if our app is in Angular.
- Copy paste code on EC2 instance and install all dependencies.
- Start server to run.
OR:
- Build Spring boot app in the local machine. Make .jar file.
- Upload this .jar on S3.
- Create EC2 instance.
- SSH into it from the local computer. Now, we are in EC2 instance.
- We can install JDK now.
- And using java - .jar file path, we can run our application.
Question 4:
Why should we use ThreadPoolExecutor, when we have Executor Framework?
Answer:
Source code of Executors.newFixedThreadPool() is:
public static ExecutorService newFixedThreadPool(int nThreads){
return new ThreadpoolExecutor(nThreads, nThreads, oL, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
}
This method uses ThreadPoolExecutor class which uses default configuration as is seen in above code.
Now, there are scenarios where default configuration is not suitable, say instead of LinkedBlockingQueue, a PriorityQueue needs to be used etc.
In such cases, caller can directly work on underlying ThreadPoolExecutor by instantiating it and passing desired configuration to it.
Note: One advantage of using ThreadPoolExecutor is that we can handle RejectedExecutionException using ThreadPoolExecutor.discardPolicy().
Question 5:
What is the difference between Spring 2 and Spring 5?
Answer:
Below are the differences between Spring 2 and Spring 5:
- JDK baseline update
- Core framework revision
- Reactive programming model
- Core Container updates
- Testing improvements
Question 6:
What is the difference between @SpringBootApplication and @EnableAutoConfiguration?
Answer:
Following are the differences between @SpringBootApplication and @EnableAutoConfiguration:
Availability: @SpringBootApplication was introduced in version 1.2, while @EnableAutoConfiguration was introduced in version 1.0.
Purpose: @EnableAutoConfiguration enables auto configuration feature of Spring Boot application which automatically configures things if certain classes are present in classpath e.g. it can configure Thymeleaf TemplateResolver and ViewResolver if Thymeleaf is present in the classpath.
On the other hand, @SpringBootApplication does three things:
- It allows us to run the main class as a jar with an embedded container [Web server Tomcat].
- It enables java configuration.
- It enables component scanning.
Question 7:
What happens when we call SpringApplication.run() method in main class of SpringBoot application?
Answer:
Syntax of the class containing main method looks like code below:
@SpringBootApplication
public class StudentApplication{
public static void main(String[] args){
return SpringBootApplication.run(StudentApplication.class, args);
}
}
When we run this class as a java application, then our application gets started.
SpringApplication.run() is a static method and it returns an object of ConfigurableApplicationContext.
ConfigurableApplicationContext ctx = SpringApplication.run(StudentApplication.class, args);
Thus, Spring container gets started once run() method gets called.
Spring container once started is responsible for:
- Creating all objects: This is done by @ComponentScan. Remember @SpringBootApplication is a combination of @ComponentScan + @Configuration + @EnaleAutoConfiguration
- Dependency Injection
- Managing the lifecycles of all beans.
That's all for this post.
Thanks for reading!!
No comments:
Post a Comment