From 00b45c11a422323cfa20891894a67bae8deb3a47 Mon Sep 17 00:00:00 2001 From: siddheshmhatrecollege Date: Thu, 29 Jan 2026 14:05:10 +0530 Subject: [PATCH] first commit --- Multi.class | Bin 0 -> 509 bytes Multi.java | 10 ++++++++++ Multi3.class | Bin 0 -> 611 bytes Multi3.java | 12 ++++++++++++ MultipleThread.java | 33 +++++++++++++++++++++++++++++++++ MyThread.java | 25 +++++++++++++++++++++++++ RunnableTest.class | Bin 0 -> 565 bytes RunnableTest.java | 19 +++++++++++++++++++ TestMultiPriority1.java | 15 +++++++++++++++ ThreadExample1.class | Bin 0 -> 1017 bytes ThreadExample1.java | 13 +++++++++++++ p1.java | 10 ++++++++++ x$RunnableTest.class | Bin 0 -> 769 bytes x.class | Bin 0 -> 941 bytes 14 files changed, 137 insertions(+) create mode 100644 Multi.class create mode 100644 Multi.java create mode 100644 Multi3.class create mode 100644 Multi3.java create mode 100644 MultipleThread.java create mode 100644 MyThread.java create mode 100644 RunnableTest.class create mode 100644 RunnableTest.java create mode 100644 TestMultiPriority1.java create mode 100644 ThreadExample1.class create mode 100644 ThreadExample1.java create mode 100644 p1.java create mode 100644 x$RunnableTest.class create mode 100644 x.class diff --git a/Multi.class b/Multi.class new file mode 100644 index 0000000000000000000000000000000000000000..b711cc4783fde3f310b778089916bd143c6f4837 GIT binary patch literal 509 zcmZuu+e*Vg5Ixg0&BgR?>s_lLw2JlvD!zz5RS{YW;!|ovT}d{QCW4=(4=pJ80e+M? zn<7Q%!|u+`oO9;v?Dx;d7l2C~*vLRLkaeIVM<_kHFK*j+<+$B{j68Ql$ejr(;&X!5 zYz-`!ungD^R^a@D_g*Kl7ceSJVnVH(3W>0N8wnZrV%7>eCJKb|T(}`7jVO^)$gzzQ z$_6S9s#qmdmrx1Dvl8+pYd7cOsY_O7g-&Z=pia=Q6F(L)?Q z9wZ1`9PRK)Dswagy>UR;=3SM+1Y*D+^f0{x);o+!ev0A(uD%G!^5k_`*u@?bmHG+i fRVDw4+T9Fm-Qy|N7qmiZ#$cKWhl#{CRoDGrK$Tv~ literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..ff5ba95b5695b51e9e207f075f33fcd6faafc32a GIT binary patch literal 611 zcmZva$xZ@65QhH-WSC)GSltyD6x6`Mn;I`hPq;(~3Gp=O1e*+v8G1~7EImLXi4WjI z8LKdgCLU&b`|GQ}s{8%p^$ox&iWWi$8;IDLKvZC+?L0bV&rz-NWwY(xYJupHR8k)c zgbT&Gi5N@+mW?>8kc!r*jy?lt5bF)8Z~CdpSQ) zN~%_=RI)IGgn^`u6w(5zf1(A92WEMS@P#k_$SA=Ha#*Yz$dcXjz|(TyLWb*_|KqVX z%4}f{i(K!L!0d0(HQ8~Ro=Yg!tk_uPo=o(#<7)$J0?BcEzQqEOlkS}>FkO+#y$Cu@ z*RL^!T0!;EamSG~WD7U{c^0s$-N3(f&m@P$zucEN4{}sP2!ci+Ods74t=4I_OrzkP zodLu%O$0XR&&Mnk*!+>^M+m@tfsvf-V|py-yJu>Q#3u6CqCln}5Q6h%hsZPrn5_&k g*Vr9k;e4-;<#Bux5mLqYNgx64c$^5^v=>6*6GPQ_>i_@% literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..99060c21dcd760a6f57a6d5a29059701bff93f60 GIT binary patch literal 565 zcmY+BT~8W86o#Jz;=;NLXu;O1#cymI`2m{VGYLQXbz^qvo)BddXLXw*F z2l%6!p3zt#lgyl%Ip=xbnREa5_aESpx=)6z$5cR$X`yr#-h_=_XfGOHI#=c_6{Zg& z8>JtFY<>5{BQMBzAJ0|IOcb;)6BBlQd}bYOPFSorpLxeaYr{^@?C+kqoKis9Ddq-g zn4|?3c;QhAsIoXgZT%RermyPpP|Z{xfl=J}nnX5jr7GFq&+|%HYG0b#q3zb<^IEE5 zKa8vfkDgw$?6DHC${S(f!PF!}@U9)PXH{g}wn{|yLQQ+D3Bl7V+Ge13ras19BNUsF zHJ^w5j!D|?iF)DGg=+oV*bn?i34SXcCTHd-a>?a!=$Z=@J>e*ns@l8??wcl-rrLE#r*usTb7;~RqYwf Vl4njkQ=~#k<;qIi*7FQI{{Z}lcKQGS literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..03a650e1c8349eada25aba637a02070888984c4f GIT binary patch literal 1017 zcmaJ=+fEZf82*NByY0F_p>jUBDrgHr#lww7E^HuT>LF=^G2S?|BP{IBG`mxjH}N&} z0uoGo03XWuPZ!gY60_O)=kR^sf13II=i(QDZ9H`_1j|OsMH(4~{1HFl<$%kBa^o-( zyv2~&^rf%27_4GxFNZ90HXIi>;9h~(Ph%}YLaB~sn5cDyd{urI`BK+4X@!+6Mi|Bt zVb71fs3WB>4;6*H9Vkwh;;>X%`dmZj_`<3YF5{IOQ|xVhYm?Qz1VV zRVABTzxVYa&0@`^jtzIWG|09w%P^9}wf&Wc?Lcfen1N-61s98^G-=X^D792owFJXx z&6na$C)^iNgYO5lV^KPE9CDw`WbxympVA(KQ&*j+DRz8ADO~lrZZfB;zEDcXI^ylu zLLaJDoJEmgy50#r_1V*3lqb7>W2)gZkBw%q;$RgIY^<3AtTQb2+UUy@bu7wBosydD z@TOMLDZ{t^N?rmJmoK?&1tMOmDRtawR|Zq*+qpt)oVLX^@cv@F-9HjdUFq+`r9_nn zLEYD)!r<;oDWYn?<558;=MNoQI(gh-SRG8by(h+Y_{LV`2CgT_xzcnO z_Y7=UXy87>^1R7K3a!z+j9~m;c;g~aA z>w1Fs;$Xz(KzB>M9B?%W$A_+T1FpEFVP&*7hPrc-7|0(Y2D2Z=@|5p;y1tqu+|kk* z@;xGd5o!U}OCh-2_1!4q1Z^d=VPli#tFIJ2ML1-en>S literal 0 HcmV?d00001 diff --git a/x.class b/x.class new file mode 100644 index 0000000000000000000000000000000000000000..8321f7fc96962732251211c3723a044d611e2d28 GIT binary patch literal 941 zcmaJ=L2nX46#fP(3+q-|5GrDITd6|Tq8_F3AZcS0szykS@if3#wk$JbceatcKf=2Q z&w9|L2Y-OS#b02I`j$mY1Mx8X-n@C=_q}=h=G(86uK;#%-$V>?0}B?;A;GY8#E*H^ zr8rcKWl<3F%jI)R%e%BUFF3|n`Lp>$fHBac;IRHGh6-Q49Jt-KM#yXh88 z5+kw4Ty|aIml{g-gJEs9Q&W*Mz}9Fe=A^%x%8$mTHvI=D6m{;pO-G9wgS986@aiu2 zec>C}V%V6u)4Wm*+-11>|5TdT=w7f