Monday, 14 April 2014

JAVA Programs To Implement The Design Multithread Program


Write a JAVA Programs To Implement The Design Multithread Program


Ex: No: 15 DESIGN MULTITHREAD PROGRAM IN JAVA

Aim:To write a JAVA programs to implement the design multithread program.

Algorithm:

Step 1: Start the program.
Step 2: Create the thread class.
Step 3: Create the main class thread.
Step 4: Create the memory space.
Step 5: Execute the program.
Step 6: Display the output.
Step 7: Stop the program


Program:

public class CurrentThreadDemo1
{
public static void main(String args[])
{
Thread t=Thread.currentThread();
System.out.println("current thread:"+t);
t.setName("my thread");
System.out.println("after name change:"+t);
try
{
for(int n=5;n>0;n--)
{
System.out.println(n);
Thread.sleep(1000);
}
}
catch(InterruptedException ie)
{
System.out.println("main thread interrupted");
}
}
}


Output:

Current Thread: Thread [Main, 5, Main]
After Name Change: Thread [My Thread, 5, Main]
5
4
3
2
1

Result:

Thus the implementation of JAVA program for design multithread program is executed and the output has been verified.



0 comments:

Post a Comment