File tree Expand file tree Collapse file tree
core-java/src/com/coderbd/ex71/threads Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .coderbd .ex71 .threads .ex1 ;
2+
3+ import java .util .logging .Level ;
4+ import java .util .logging .Logger ;
5+
6+ public class HelloRunner implements Runnable {
7+ int i ;
8+ @ Override
9+ public void run () {
10+ i =0 ;
11+ while (true ) {
12+ System .out .println ("Hello: " +i ++);
13+ if (i ==50 ){
14+ break ;
15+ }
16+ try {
17+ Thread .sleep (3000 );
18+ // break;
19+ } catch (InterruptedException ex ) {
20+ Logger .getLogger (HelloRunner .class .getName ()).log (Level .SEVERE , null , ex );
21+ }
22+ }
23+ }
24+
25+ }
Original file line number Diff line number Diff line change 1+ package com .coderbd .ex71 .threads .ex1 ;
2+
3+ public class ThreadTest {
4+
5+ public static void main (String [] args ) {
6+ HelloRunner r = new HelloRunner ();
7+
8+ Thread t1 = new Thread (r );
9+ t1 .setPriority (10 );
10+ t1 .start ();
11+ Thread t2 = new Thread (r );
12+ t2 .start ();
13+
14+
15+ System .out .println ("t1 Pririty " +t1 .getPriority ());
16+ System .out .println ("t2 Pririty " +t2 .getPriority ());
17+ System .out .println ("t1 Name " +t1 .getName ());
18+ System .out .println ("t2 Name " +t2 .getName ());
19+
20+ }
21+
22+ }
Original file line number Diff line number Diff line change 1+ package com .coderbd .ex71 .threads .ex2 ;
2+
3+ import java .lang .Thread .State ;
4+
5+ public class App {
6+
7+ public static void main (String [] args ) {
8+ Uncle uncle = new Uncle ();
9+ Thread uncleThread = new Thread (uncle );
10+ uncleThread .setName ("Mr. Jamil" );
11+ uncleThread .setPriority (1 );
12+ uncleThread .start ();
13+ Urmi u = new Urmi ();
14+ Thread urmiThread = new Thread (u );
15+ urmiThread .setName ("Urmi" );
16+ urmiThread .setPriority (10 );
17+ urmiThread .start ();
18+ System .out .println ("uncleThread Name " + uncleThread .getName ());
19+ System .out .println ("urmiThread name " + urmiThread .getName ());
20+ System .out .println ("uncleThread Priority " + uncleThread .getPriority ());
21+ System .out .println ("urmiThread Priority " + urmiThread .getPriority ());
22+ }
23+
24+ }
Original file line number Diff line number Diff line change 1+ package com .coderbd .ex71 .threads .ex2 ;
2+
3+ import java .util .logging .Level ;
4+ import java .util .logging .Logger ;
5+
6+ public class Uncle implements Runnable {
7+
8+ int i ;
9+
10+ @ Override
11+ public void run () {
12+ i = 0 ;
13+ while (true ) {
14+ System .out .println ("Uncle: " + i ++);
15+ if (i == 50 ) {
16+ break ;
17+ }
18+ /* try {
19+ Thread.sleep(1);
20+ } catch (InterruptedException ex) {
21+ Logger.getLogger(Uncle.class.getName()).log(Level.SEVERE, null, ex);
22+ }*/
23+ }
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ package com .coderbd .ex71 .threads .ex2 ;
2+
3+ public class Urmi implements Runnable {
4+ int i ;
5+ @ Override
6+ public void run () {
7+ i = 0 ;
8+ while (true ) {
9+ System .out .println ("Urmi: " + i ++);
10+ if (i == 50 ) {
11+ break ;
12+ }
13+
14+ }
15+ }
16+ }
You can’t perform that action at this time.
0 commit comments