class Deadlock {
public static void main(String[] args) {
final String r1 = "R1", r2 = "R2";
new Thread(() -> {
synchronized(r1){
try{
Thread.sleep(100);
}
catch(Exception e){}
synchronized(r2){}
}
}).start();
new Thread(() -> {
synchronized(r2){
try{
Thread.sleep(100);
}
catch(Exception e){}
synchronized(r1){}
}
}).start();
System.out.println("Deadlock created!");
}
}
//Program to display table data
import java.sql.*;
class JdbcExample {
public static void main(String[] args) throws Exception {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/test","root","pass");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from student");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2));
con.close();
}
}