Skip to main content
Home
Live to Learn!

Main navigation

  • Home
  • Learn
    • FoxPro
    • MS-DOS
    • C PRG
    • Java
    • ASP
    • Ruby on Rails
    • ASP.NET
    • E-Books
    • Exam Preparation
    • Tools
  • Blog
  • Forums
  • Contact
User account menu
  • Log in

Breadcrumb

  1. Home
  2. Learn by Example - Java Sample Programs

Simple Multithread program

Book navigation

  • Armstrong Number
  • Palindrome Checking
  • Playing Audio Clip using Applet
  • Applet Form
  • Exception Handling
  • Multiple Inheritance and Packages
  • Shopping List
  • Simple Multithread program
  • JDBC Program Select, Insert, Update, Delete records
  • RMI - Example AddServer
  • Simple Bank Account Process
  • TCP Server and Client in Java
  • UDP Server and Client in Java
  • FTP Server and Client in Java
  • Chat Server and Client in Java
  • Echo Server and Client in Java
  • Address Resolution Protocol in Java
  • Ping server and Client in Java
  • Multicast Server and Client in Java
  • Transposition Cipher Method
  • Poly-alphabetic Cipher Method Encryption - Java
  • DES - Using Data Encryption Standard in Java
  • AES - Using Advanced Encryption Standard in Java
  • Bit Stuffing
By Karthik , 25 November, 2011

import java.io.*;
class patient implements Runnable
{
    Thread t;
    String n;
    patient(String name)
    {
        n = name;
        t = new Thread(this);
        t.setName(name);
        t.start();
    }
    synchronized void attend()
    {
        try
        {
            System.out.println("Doctor is diagnosing the patient :" +n);
            Thread.sleep(1500);
        }
        catch(InterruptedException e)
        {
            System.out.println("Extension interrupted");
        }

    }
    public void run()
    {
        attend();
    }
}
class muldemo
{
    public static void main(String args[]) throws IOException
    {
        patient in[] = new patient[10];
        int count = 0;
        int w = 0;
        System.out.println("Hospital Simulation");
        try
        {
            do
            {
                String name = getstring();
                System.out.println("Name of the patient:"+name);
                System.out.println("Waiting time in mins :" +w);
                in[count] = new patient(name);
                Thread.sleep(2000);
                System.out.println("Two mins rest for doctor");
                        w+=12;
                        count++;
            }
            while(count<5);
        }
        catch(InterruptedException e)
        {
            System.out.println("Exception Interrupted");
        }
    }
    public static String getstring() throws IOException
    {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        String s = br.readLine();
        return(s);
    }
}
  • Add new comment

Comments

Featured Blog Posts

Convert Currency in Number to Words (Indian Rupees) - MS Excel
Foxpro Tutorial and Programs
Convert Currency in Number to Words in MS Word
Convert Currency in Number to Words (Indian Rupees) - Version 2
Best way to Use Rupee Symbol in Windows – Easy steps
Convert Currency in Number to Words - MS Access
Creating All in One Windows XP DVD with all Important Applications
RSS feed

© 2009-2025 Live to Learn.In

Terms of Use | Privacy Policy