commit 00b45c11a422323cfa20891894a67bae8deb3a47 Author: siddheshmhatrecollege Date: Thu Jan 29 14:05:10 2026 +0530 first commit diff --git a/Multi.class b/Multi.class new file mode 100644 index 0000000..b711cc4 Binary files /dev/null and b/Multi.class differ diff --git a/Multi.java b/Multi.java new file mode 100644 index 0000000..6aa1edc --- /dev/null +++ b/Multi.java @@ -0,0 +1,10 @@ +// write a java code by extending thread class +class Multi extends Thread{ + public void run(){ + System.out.println("Thread is running"); + } + public static void main(String args[]){ + Multi t1 = new Multi(); + t1.start(); + } +} diff --git a/Multi3.class b/Multi3.class new file mode 100644 index 0000000..ff5ba95 Binary files /dev/null and b/Multi3.class differ diff --git a/Multi3.java b/Multi3.java new file mode 100644 index 0000000..55bedd5 --- /dev/null +++ b/Multi3.java @@ -0,0 +1,12 @@ +// write a java code by implementing runnable interface. + +class Multi3 implements Runnable{ + public void run(){ + System.out.println("thread is running..."); + } + public static void main(String args[]){ + Multi3 m1 = new Multi3(); + Thread t1 = new Thread(m1); + t1.start(); + } +} diff --git a/MultipleThread.java b/MultipleThread.java new file mode 100644 index 0000000..2881bf2 --- /dev/null +++ b/MultipleThread.java @@ -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); + } +} diff --git a/MyThread.java b/MyThread.java new file mode 100644 index 0000000..c996e31 --- /dev/null +++ b/MyThread.java @@ -0,0 +1,25 @@ +// write a java code for two thread performing two task at a time +public class MyThread extends Thread{ + String task; + MyThread(String task){ + this.task = task; + } + public void run(){ + synchronized(this) { + for(int i=1;i<=5;i++){ + System.out.println(task + ":" + i); + try { + Thread.sleep(1000); + }catch(InterruptedException ie){ + System.out.println(ie.getMessage()); + } + } + } + } + public static void main(String args[]){ + MyThread th1 = new MyThread("Cut the ticket"); + MyThread th2 = new MyThread("Show your seat number"); + th1.start(); + th2.start(); + } +} diff --git a/RunnableTest.class b/RunnableTest.class new file mode 100644 index 0000000..99060c2 Binary files /dev/null and b/RunnableTest.class differ diff --git a/RunnableTest.java b/RunnableTest.java new file mode 100644 index 0000000..430b41a --- /dev/null +++ b/RunnableTest.java @@ -0,0 +1,19 @@ +class x implements Runnable{ + public void run(){ + for(int i=0;i<=5;i++){ + System.out.println("The Thread x is: " + i); + } + + System.out.println("End of the Thread x"); + } +} + +class RunnableTest{ + public static void main(String args[]){ + x r = new x(); + Thread threadx = new Thread(r); + threadx.start(); + System.out.println("The End of the main thread"); + } +} + diff --git a/TestMultiPriority1.java b/TestMultiPriority1.java new file mode 100644 index 0000000..1ebc54a --- /dev/null +++ b/TestMultiPriority1.java @@ -0,0 +1,15 @@ +// write a java code for demonstrating thread priority +class TestMultiPriority1 extends Thread{ + public void run(){ + System.out.println("running thread name is: " + Thread.currentThread().getName()); + System.out.println("running thread priority is: " + Thread.currentThread().getPriority()); + } + public static void main(String[] args) { + TestMultiPriority1 m1 = new TestMultiPriority1(); + TestMultiPriority1 m2 = new TestMultiPriority1(); + m1.setPriority(2); + m2.setPriority(Thread.MAX_PRIORITY); + m1.start(); + m2.start(); + } +} diff --git a/ThreadExample1.class b/ThreadExample1.class new file mode 100644 index 0000000..03a650e Binary files /dev/null and b/ThreadExample1.class differ diff --git a/ThreadExample1.java b/ThreadExample1.java new file mode 100644 index 0000000..2501df0 --- /dev/null +++ b/ThreadExample1.java @@ -0,0 +1,13 @@ +public class ThreadExample1 extends Thread{ + public void run(){ + int a = 0; + int b = 12; + int result = a + b; + System.out.println("Thread is running"); + System.out.println("Sum of two numbers is: " + result); + } + public static void main(String args[]){ + ThreadExample1 t1 = new ThreadExample1(); + t1.start(); + } +} diff --git a/p1.java b/p1.java new file mode 100644 index 0000000..b83df58 --- /dev/null +++ b/p1.java @@ -0,0 +1,10 @@ +// write a java code by extending thread class +class Multi extends Thread{ +public void run(){ + System.out.println("Thread is running"); +} +public static void main(String args[]){ + Multi t1 = new Multi(); + t1.start();' +} +} diff --git a/x$RunnableTest.class b/x$RunnableTest.class new file mode 100644 index 0000000..c3bb646 Binary files /dev/null and b/x$RunnableTest.class differ diff --git a/x.class b/x.class new file mode 100644 index 0000000..8321f7f Binary files /dev/null and b/x.class differ