• Call Us: +91 9437911966
  • Email Us: info@studentstutorial.com
  • Home
  • C Examples
  • Server Side
    • PHP
    • Java
    • CodeIgniter
    • Laravel
    • JSP
    • JDBC
  • Frontend
    • HTML
    • CSS
    • Javascript
    • jQuery
    • AJAX
    • FPDF
    • TCPDF
  • APP & DB
    • Android
    • Cordova
    • SQL
    • Oracle
  • Project
Java Introduction System.out.println(): Program for input through console Program for addition Program for Subtraction Program for Multiplication Program for Division Program for modulus Program for increment Program for percentage Program for square Program for cube Program for square root Check Even or Odd Reverse of a number Find prime numbers Find factorial Program for palindrome Program for Diamond Star Program for Pascal Star Program for Fibonacci Series Find largest number Find Smallest number Find largest third number Find largest second number Program for Bubble Sort Program for Insertion Sort Program for Selection Sort Program for Linear Search Program for Binary Search Find IP address Open notepad through java program Find Armstrong Number Find mirror clock Comparing Value create Backup file Program for file content modifier Program for copying files Fahrenheit to Celsius create deadlock program Implement hashcode program Convert File to Zip Remove Duplicate Element From Array Java Matrix Addition Java Matrix Multiplication

Java Program to create deadlock between two threads

  • Students Tutorial
   

Deadlock.java

import java.io.BufferedOutputStream;
public class Deadlock {
 
    String str1 = "Students";
    String str2 = "Tutorial";
     
    Thread th1 = new Thread("My Thread 1"){
        public void run(){
            while(true){
                synchronized(str1){
                    synchronized(str2){
                        System.out.println(str1 + str2);
                    }
                }
            }
        }
    };
     
    Thread th2 = new Thread("My Thread 2"){
        public void run(){
            while(true){
                synchronized(str2){
                    synchronized(str1){
                        System.out.println(str2 + str1);
                    }
                }
            }
        }
    };
     
    public static void main(String a[]){
        Deadlock dl = new Deadlock();
        dl.th1.start();
        dl.th2.start();
    }
}

Student Tutorial is a online tutorial for web design and development. Here you can find easy example and explanation for each tutorial.
Copyright © 2016-2023 Student Tutorial

Server Side

  • PHP
  • Java
  • CodeIgniter
  • Laravel
  • JSP
  • JDBC

Frontend

  • HTML
  • CSS
  • Javascript
  • jQuery
  • AJAX
  • FPDF

App & Database

  • Android
  • Cordova
  • SQL
  • Oracle