1- CountDownLatch
2-CyclicBarrier
3- Phaser
4-Exchanger
5-Semaphore
6-SynchronousQueue

1-CountDownLatch- it was added to the Java 5 concurrency package.

It allows one or more threads to wait until a set of operations being performed in other threads are completed

C:\Users\sanjsingh>javap java.util.concurrent.CountDownLatch
public class java.util.concurrent.CountDownLatch {
public java.util.concurrent.CountDownLatch(int);
public void await() throws java.lang.InterruptedException;
public boolean await(long, java.util.concurrent.TimeUnit) throws java.lang.InterruptedException;
public void countDown();
public…


Transaction simply represents a unit of work ,In such case, if one step fails, the whole transaction fails.

Hibernate Transaction Management

Transaction simply represents a unit of work ,In such case, if one step fails, the whole transaction fails.

Transaction is a Interface in Hibernate

  • The methods of Transaction interface are as follows:
    * void begin() starts a new transaction.
    * void commit() ends the unit of work unless we are in FlushMode.NEVER.
    * void rollback() forces this transaction to rollback.
    * boolean wasCommited() checks if the transaction is commited successfully.
    * boolean wasRolledBack() checks if the transaction is rolledback successfully.

A transaction is associated with Session and instantiated by calling session.beginTransaction().

Example of Transaction Management in Hibernate

Session session = null;
Transaction tx = null;
try {
session = sessionFactory.openSession();
tx = session.beginTransaction();
(Bussiness Logic)
tx.commit();
}catch (Exception ex) {
ex.printStackTrace();
tx.rollback();
}
finally {session.close();}

Transaction associated with Dao layer


Export table in csv file By Using mysql command

SHOW VARIABLES LIKE “secure_file_priv”;
SELECT * FROM bootapplication into outfile ‘/ProgramData/MySQL/MySQL Server 8.0/Uploads/mysql_processes.csv’;

Export table in csv file by using workbench

Step1-

Step 2-


download Lombok jar
https://projectlombok.org/download

Goto lombok jar download location and run command
java -jar lombok-1.16.18.jar

Give Lombok Install Path
click on the “Specify Location” button and locate the eclipse.exe


Step 1: Generate Your SSH Key
ssh-keygen -t rsa -b 4096 -C “youreamil@example.com

SSH Key on Windows
$ eval $(ssh-agent -s)
$ ssh-add ~/.ssh/id_rsa

Step 3: Add the SSH Key on GitHub
clip < ~/.ssh/id_rsa.pub

step 4 add ssh key in github/gitlab

/c/Users/****user name ****/.ssh/id_rsa.pub.


Step 1 — Run your Spring boot application
Step 2 -http://localhost:9001/h2-console/
port no- Application port no (9001)
Step 3- JDBC URL ,username and password application.yml or properties file

H2 Console on browser
H2 console
application.ymlserver:
port: 9001
spring:
application:
name: product-services
datasource:
driver-class-name: org.h2.Driver
password: password
url: "jdbc:h2:file:~/products;AUTO_SERVER=true"
username: root
h2:
console:
enabled: true
jpa:
databae-platform: org.hibernate.dialect.H2DDialect
hibernate:
ddl-auto: update


https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/beans/BeanUtils.html

Static convenience methods for JavaBeans: for instantiating beans, checking bean property types, copying bean properties, etc.

Case 1- when you need to copy field value from one object to another object

public ProductAggregate(CreateProductCommand createProductCommand) {

ProductCreatedEvent productCreatedEvent = new ProductCreatedEvent();
BeanUtils.copyProperties(createProductCommand,productCreatedEvent);

}
// CreateProductCommand object value copy in ProductCreatedEvent
Copy the property values of the given source bean into the target bean.


@Transactional — class level and Method level both We are now ready to use @Transactional annotation either at the class or method level.

if you are using JDBC then it will work on DAO layer, but if you are working on JPA or Spring Data then it works on service…


Using BufferedReader object to read the input text file.\

Step 1 : Create BufferedReader object to read the input text file.
BufferedReader reader = new BufferedReader(new FileReader(“Pass The File Location Here”));
Step 2 : Create one ArrayList object which will hold all the lines or records of input text file.
ArrayList<String> lines =…


/*find all the permutations of a string*/
public class PrintAllPermutations {
public static void permutation(String name, String blank) {
if (name.length() == 0) {
System.out.println(blank);
}
for (int i = 0; i < name.length(); i++) {
String newBlank = blank + name.charAt(i);
String newRemaining =.name.substring(0, i) + name.substring(i + 1);
permutation(newRemaining…

Sanjay Singh

Java||Spring-Boot|| Micro services Application developer|| angular || INDIA

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store