first commit

This commit is contained in:
2026-01-29 14:05:10 +05:30
commit 00b45c11a4
14 changed files with 137 additions and 0 deletions

33
MultipleThread.java Normal file
View File

@@ -0,0 +1,33 @@
// write a java program for multiple thread acting on a single object
public class MultipleThread implements Runnable{
String task;
MultipleThread(String task){
this.task = task;
}
public void run(){
for(int i=0;i<=5;i++){
System.out.println(task + ":" + i);
try{
Thread.sleep(1000);
}catch(InterruptedException e){
e.printStackTrace();
}
}
}
public static void main(String args[]){
Thread nThread = Thread.currentThread();
System.out.println("Name of the Thread: " + nThread);
MultipleThread mt = new MultipleThread("Hello Java");
Thread t1 = new Thread(mt);
Thread t2 = new Thread(mt);
Thread t3 = new Thread(mt);
t1.start();
System.out.println("thread" + t1 );
t2.start();
System.out.println("thread " + t2);
t3.start();
int count = Thread.activeCount();
System.out.println("No of active threads: " + count);
}
}