0% found this document useful (0 votes)
28 views2 pages

Q & A

1. This document discusses how to run a cron job every 2 months. It provides the cron expression to use: 0 0 1 */3 * 2. It explains the components of a cron expression, such as the minute, hour, day of month, month, and day of week. 3. The document also contains questions and answers about topics like marker interfaces in Java, functional interfaces, exceptions in Spring Boot, and connecting microservices using Apache Kafka.

Uploaded by

santhosh kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views2 pages

Q & A

1. This document discusses how to run a cron job every 2 months. It provides the cron expression to use: 0 0 1 */3 * 2. It explains the components of a cron expression, such as the minute, hour, day of month, month, and day of week. 3. The document also contains questions and answers about topics like marker interfaces in Java, functional interfaces, exceptions in Spring Boot, and connecting microservices using Apache Kafka.

Uploaded by

santhosh kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

how to run job every 2 mnts by using cron job

soln: */2 * * * *

Every 2 hours --> 0 */2 * * *


Every 3 months --> 0 0 1 */3 *
1* minutues(0-59)
2*Hour(0-23)
3*Dayofthemonth(1-31)
4*month(1-12)
5*Dayoftheweek(0-6)(Sunday to Saturday;7 is also Sunday on some systems)

Q)What is Marker Interface


A marker interface in Java is an empty interface with no fields or methods. It has
three types:
Serializable interface
Cloneable interface
Remote interface

Q) capacity = number of buckets * load factor


Q) index = hashcode(key) & (n-1) where n is no.of buckets
bucket->node->linkedlist = key,hashcode,value,next(address of the next node)
Q) Markable interfaces in java
marker interface is an interface that doesn't contain any methods
1.serializable 2.clonable 3. randomAccess 4. remote
Q) Functional interfaces before java 8
1.Runnable 2.Callable 3.ActionListener 4.Comparable 5.Comparator.
Q) Functional Interface?
An Interface that contains exactly one abstract method is known as functional
interface. It can have any number of default, static methods but can contain only
one abstract method. It can also declare methods of object class. Functional
Interface is also known as Single Abstract Method Interfaces or SAM Interfaces.
Q) How to know Thread is completed or not
By using isAlive() mrhtod we can check
To confirm if the thread has completed, you can use the isAlive() method. It
returns true if the thread is still running, and false if the thread has completed
its execution.

if (myThread.isAlive()) {
System.out.println("The thread is still running.");
} else {
System.out.println("The thread has completed.");
}
Q) How to add another server in spring boot?
By using exclusion first we can exclude exsting server and add new server
dependency
<dependency>
<groupid>org.springframework.boot</>
<artifactid>spring-boot-starter-web</>
<exclusions>
<exclusion>
<groupid>org.springframework.boot</>
<artifactid>spring-boot-starter-tomcat</>
</exclusion> </exclusions>

</dependency>
Q) how to handle exceptions in spring boot ?
we use this for custom exceptions @ExceptionHandler(CustomException.class)
Q) How to connect multiple microservices
we two types 1.synhronous and 2.asynchronous
1.by using rest template and feign
2.by using Message Brokers like Apache Kafka,Active MQ or
RabbitMQ etc.
Q) Connecting multiple microservices using Apache Kafka
Set up Apache Kafka:
Install and set up Apache Kafka on your local machine or
infrastructure.
Create a Kafka topic that will be used for communication between
microservices.
Add Kafka dependency:the following dependency to your pom.xml (if using
Maven)
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
Configure Kafka connection:
In each microservice, add the following properties to your
application.properties or application.yml file, specifying the connection details
for Apache Kafka: in yaml file
spring.kafka.bootstrap-servers=localhost:9092
Create a message producer:
In the microservice that wants to send messages, create a component or
service that will act as the message producer.
Create a message consumer:
In the microservice that wants to receive messages, create a component
or service that will act as the message consumer.
The @KafkaListener annotation is used to indicate that this method
should listen for messages from the specified topic, which is configured in the
application properties.
Send and receive messages:
In your microservice code, you can now use the MessageProducer
component to send messages and the MessageConsumer component to receive messages.
By following these steps, you can establish communication between multiple
Spring microservices using Apache Kafka as the messaging system. The message
producer sends messages to a specified Kafka topic, and the message consumer
listens for and processes messages from the same topic.

You might also like