Java Blog

 
 
 
class Arr
{
   int int_array[]=new int[5];
   synchronized void add_to_array(int int_array[], int k)
   {
       for(int i=0; i<5; i++)
       {
           int_array[i]+=k;
           System.out.println(int_array[i]);
       }
   }
}

class Caller implements Runnable
{
    Arr A;
    int array[]={1, 2, 3, 4, 5};
    int val;
    Thread t;
    public Caller(Arr ar, int k)
    {
        A=ar;
        val=k;
        t=new Thread(this);
        t.start();
    }

    public void run()
    {
        System.out.println(\"Thread starts..\");
        A.add_to_array(array, val);
        System.out.println(\"Thread stops..\");
    }
}

class ThreadArrAdd
{
    public static void main(String args[])
    {
        Arr A1=new Arr();

        Caller ob1=new Caller(A1, 2);
        Caller ob2=new Caller(A1, 4);
        Caller ob3=new Caller(A1, 1);
        try
        {
            ob1.t.join();
            ob2.t.join();
            ob3.t.join();
        }
        catch(InterruptedException e)
        {
            System.out.println(\"Interrupted...\");
        }
    }
}

/* 
            OUTPUT

Thread starts..
3
4
5
6
7
Thread stops..
Thread starts..
5
6
7
8
9
Thread stops..
Thread starts..
2
3
4
5
6
Thread stops..

*/

    Related Post:
  1. Corba program to encrypt the text that you want to send on the client side. The server side decrypts it after receiving. Append server time.

  2. An applet program to display Vertical Color Bar

  3. Corba program of reverse string

  4. Program that enabled applet that takes name of the user. Server returns back the number in uppercase clubbed with “HELLO” and display it on applet

  5. Program of creating a file using text fields in windows

  6. Program for calculating area of a circle on server side,when a client sends request along with given radius and then displaying result on client side

  7. Program to show the use of Break Statement

  8. Program to show the use of Switch Statement

  9. Develop a game application in CORBA for which the player will guess a number between 1 to 100, which will be compared to the random number generated b

  10. Game application in CORBA for which player will guess a number between 1 to 100, which will be compared to the random number generated by the class

  11. An applet program showing Clicked Event on canvas

  12. Program to show the use of Bitwise Operator (&) AND

  13. Program to read command line arguments

  14. Program that takes a long sentence and a character from the client and count the occurrence of the character in the sentence at the server side

  15. Program which creates an Array of character. Make one function with one argument as a character and that function throw a user defined exception

  16. Simple Applet which will show life cycle of an Applet

  17. File handling program to display directory contents

  18. Program to show an example of creating String objects from Character Arrays

  19. Program to Display Output in triangular shape

  20. An application that combines several classes and interface