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

ex4) Java Thread - Runnable Interface

NS
normalstory
cover image


 

/*
 Runnable :run()
 -> RunnableTest :redefine run()  (+ <-automatically object:wait,notify...+run()   (+ttreference variable))
 
 => additionally a separate Thread inherit. ->t
 => tt t somewhere in "address value"must be referenced.
 
 => execution process: t->ttaddress value->tt->run()
 **/

 

public class RunnableTest implements Runnable {
 
 public void printNumber() {// method that prints numbers from 0 to 1 on screen
  for( int i=1 ; i<=20 ; i++ ) {
   System.out.println( "number = " + i );
  }
 }
  
 public void run() {// overriding run() of the Runnable interface
  printNumber();
 }
 
 public static void main( String[] args ) {
  ThreadTest tt = new ThreadTest();// create object
  
  Thread t = new Thread( tt );// create Thread class object 
  t.start();// start the Thread
  System.out.println( "--------> main thread end" );
 }
}

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.

More on the author's page

Keep reading

Renewal

Why You Should Use .html Instead of .md Seeing Is Believing

Jul 25, 2026·1 min
Renewal

The Most Important Thing About AX

Jul 17, 2026·2 min
Renewal

디지털 기술과 혁신에 대한 논고(지탱하는 힘)

Jul 17, 2026·5 min