← Back to feed
Renewal·서른의 생활코딩

ex3) Java Thread - Synchronization

NS
normalstory
cover image


 

// when using messenger ->for(;;){};not Threadby using enabling other tasks simultaneously
// server since message don't know when arriving.. continuously thread running execution,
// if using loop simultaneously other tasks not possible!

 

/*
public class ThreadTest extends Thread {
 
 public void printNumber() { // 0to screen from 0 to 1 output method
  for( int i=1 ; i<=20 ; i++ ) {
  System.out.println( "number = " + i );
  }
 }
 
 // Runnable interface run() overriding
 public void run() {
  printNumber(); //call
 } // definition
 
 public static void main( String[] args ) {
  ThreadTest tt = new ThreadTest();  // object creation
  tt.start(); // Thread start it
                 // process :
                 // JVM request -> run()execution-> 
 
                // printNumber()-> below'sSystem.out.println execution
 
 System.out.println( "--------> main thread end" );

 }
}//bug : order wrong , most last ends "main thread" must be .

**/





/*
   structure
         object :wait,notify,notifyAll
         -> Thread :start, stop  (+ <- runnable interface(public void run()))
         -> ThreadTest : parent all + printNumber()
 **/

 

 
 

/*
public class ThreadTest extends Thread {
 
 public void printNumber() { // 0to screen from 0 to 1 output method
  for( int i=1 ; i<=20 ; i++ ) {
  System.out.println( "number = " + i );
  }
 }
 
 // Runnable interface run() overriding
 public void run() {
  printNumber(); //call
 } // definition
 
 public static void main( String[] args ) {
  ThreadTest tt = new ThreadTest(); // object creation
  tt.start(); // Thread start it
                 // process :
                 // JVM request -> run()execution-> 
 
                // printNumber()-> below'sSystem.out.println execution
 
                // main()within to screen 101 120to output

  for( int i=101 ; i<=120 ; i++ ) {
  System.out.println( "-------> main number = " + i );
  }//however computer depending on performance order can.
 }
}**/

 

 


/*
public class ThreadTest extends Thread {
 
 public void printNumber() { // 0to screen from 0 to 1 output method
  for( int i=1 ; i<=20 ; i++ ) {
  System.out.println( "number = " + i );
  }
 }
 
 // Runnable interface run() overriding
 public void run() {
  printNumber(); //call
 } // definition
 
 public static void main( String[] args ) {
  ThreadTest tt = new ThreadTest();  // object creation
  tt.start(); // Thread start it
                 // process :
                 // JVM request -> run()execution->
                 // printNumber()-> below'sSystem.out.println execution
                 // main()within to screen 101 120to output
 

  tt.join();   //-> try catch codeblockneeded!
  }
 }
}**/

 

 

 

/*
public class ThreadTest extends Thread {
 
 public void printNumber() { // 0to screen from 0 to 1 output method
  for( int i=1 ; i<=20 ; i++ ) {
  System.out.println( "number = " + i );
  }
 }
 
 // Runnable interface run() overriding
 public void run() {
  printNumber(); //call
 } // definition
 
 

 public static void main( String[] args ) {
 

  ThreadTest tt = new ThreadTest(); // object creation
  tt.start(); // Thread start it
 

  try{
   tt.join();
  }catch(InterruptedException e){}
 

  System.out.println( "-------> main number = ");
 }

}**/

 

 

 

/*
public class ThreadTest extends Thread {
 
 public void printNumber() { // 0to screen from 0 to 1 output method
  for( int i=1 ; i<=20 ; i++ ) {
  System.out.println( "number = " + i );
  }
 }
 
 // Runnable interface run() overriding
 public void run() {
  System.out.println(Thread.currentThread());//orderof
  printNumber(); //call
 } // definition
 
 public static void main( String[] args ) {
 

  ThreadTest tt = new ThreadTest();  // object creation
  tt.start();// Thread start it
  System.out.println(tt.getPriority());//orderof
 

  try{
   tt.join();
  }catch(InterruptedException e){}
 

  System.out.println( "-------> main number = ");
 }
}**/

 

 


public class ThreadTest extends Thread {
 
 public void printNumber() {
  for( int i=1 ; i<=20 ; i++ ) {
  System.out.println( "number = " + i );
  }
 }
 

 public void run() {
  System.out.println(Thread.currentThread());
  printNumber(); 
 } 
 
 public static void main( String[] args ) {
  ThreadTest tt = new ThreadTest();
  tt.start();
  tt.setPriority(9); // priority specify!!!
  System.out.println(tt.getPriority());
  try{
   tt.join();
  }catch(InterruptedException e){}
  System.out.println( "-------> main number = ");
 }
}

 

  • Open in Google Docs Viewer
  • Open link in new tab
  • Open link in new window
  • Open link in new incognito window
  • Download file
  • Copy link address
  • Edit PDF File on PDFescape.com

element

Font
font-family
font-size
font-style
font-variant
font-weight
letter-spacing
line-height
text-decoration
text-align
text-indent
text-transform
white-space
word-spacing
color
Background
bg-attachment
bg-color
bg-image
bg-position
bg-repeat
Box
width
height
border-top
border-right
border-bottom
border-left
margin
padding
max-height
min-height
max-width
min-width
outline-color
outline-style
outline-width
Positioning
position
top
bottom
right
left
float
display
clear
z-index
List
list-style-image
list-style-type
list-style-position
Table
vertical-align
border-collapse
border-spacing
caption-side
empty-cells
table-layout
Effects
text-shadow
-webkit-box-shadow
border-radius
Other
overflow
cursor
visibility

This English version was translated by Claude.

친절한 찰쓰씨
Written by
친절한 찰쓰씨

Pleasant Charles — UI/UX researcher at AIT. Keeping notes on design, planning, and slow days here since 2010.