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

Java Lecture Notes - 2012.02.27 (Thread)

NS
normalstory
cover image


java _20120227 (Thread) 

 

process : refers to a currently executing program.
    main memory(OS) loaded into execution unit (Word,Excel...)
thread :process smaller than execution unit means (print command,color change,font change...)

 (processor : execution running process among "current" work permission has program means.)

thread use :   1) java.lang.Thread class
  (Thread class from directly inheritancereceiving thread creation)

      class PrimeThread extends Thread {// Thread class from inheritance
            long minPrime;
            PrimeThread(long minPrime) {
                this.minPrime = minPrime;
            }
 
            public void run() {
                // compute primes larger than minPrime
                 . . .
            }
        }

  2) Runnable interface
  (current's class already other class from inheritance if exists Runnable
    interface useby thread creation can)
  (current's class already other class from inheritance case where)
  (however,Runnable interface inside, run()functiononly existbecause..
   separate's treadobject creation + "rb parametervariable by thread object tb creation")

        class PrimeRun implements Runnable {
            long minPrime;
            PrimeRun(long minPrime) {
                this.minPrime = minPrime;
            }

              public void run() {
               // compute primes larger than minPrime
                 . . .
            }
        }

thread use :  4 creation provide
  Thread()
  Thread(String s)
  Thread(Runnable r)
  Thread(Runnable r, String s)

implementation
 run() :thread execution mainand code run()not add.
  (Runnable interface inheritance)

        start():Javaon thread compose run() execution request.
  (thread class from inheritance)
 stop(): amongto(complete)(thread class from inheritance)

 wait():   amongto(object class from inheritance)
 notify(): amongto (object class from inheritance)
 notifyAll(): (object class from inheritance)
 
process start() ->"structure" among execution ->run()


Thread class method
 static void sleep(long msec)
  throws InterruptedException ->try,catshcode +InterruptedException
 void start() ->thread start. run() method call
 int getPriority() ->thread return(0~10) : monion execution orderX
            +basic(5, priority)
 void suspend() = wait
 void resume()  = notify
 



DaemonThread
other thread object end end thread object means.

 


Class ThreadGroup

 )
  tg1 ->  t1
   t2
   tg2 -> t3
       -> t4
  t execution
  gfrom , re- possible

 Constructor
  ThreadGroup(String name)
  ThreadGroup(ThreadGroup parent, String name)

 use)
 ThreadGroup TG1 = new ThreadGroup("TG1")
 ThreadGroup TG1 = new ThreadGroup("TG1","TG2")
 Thread t1 = new Thread(TG1,"t1")
 Thread t2 = new Thread(TG1,"t2")
 Thread t3 = new Thread(TG1,"t3")
 Thread t4 = new Thread(TG1,"t4")

  t1.start(); t2.start(); t3.start(); t4.start();  // execution!

 TG1.suspend(); // thatfrom
 TG1.resume();
 ...

 

 

 


synchronization(Synchronization)
 partial's programfrom thread
 but partial on usemust be
  thread synchronized method execution among other thread

 synchronized synchronization

 1) object lock lock when
  …
  synchronized(object reference variableor "this") {
  …
  }

 2)method lock lock when
  accessmodifier synchronized Resulttype function {
  …
  }


 

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

Steadily, for the long haul, without burning out

Mar 31, 2026·9 min
Renewal

Tech-life balance

Feb 7, 2026·3 min
Renewal

Humanality, by Park Jeong-ryeol

Feb 7, 2026·11 min