How traditional threads are created

Source: Internet
Author: User

Traditional Threading Technology Review

 Public classTraditionalthread {/**     * @paramargs*/     Public Static voidMain (string[] args) {//First type:new thread ()  thread thread=NewThread () {@Override Public voidrun () { while(true){                    Try{Thread.Sleep (500); } Catch(interruptedexception e) {e.printstacktrace (); } System.out.println ("1:" +Thread.CurrentThread (). GetName ()); System.out.println ("2:" + This. GetName ());        }            }        };                        Thread.Start (); Thread thread2=NewThread (NewRunnable () {@Override Public voidrun () { while(true){                    Try{Thread.Sleep (500); } Catch(interruptedexception e) {e.printstacktrace (); } System.out.println ("1:" +Thread.CurrentThread (). GetName ());        }                                            }        });                Thread2.start (); Second type:new Runnable ()          NewThread (NewRunnable () { Public voidrun () { while(true){                            Try{Thread.Sleep (500); } Catch(interruptedexception e) {e.printstacktrace (); } System.out.println ("Runnable:" +Thread.CurrentThread (). GetName ()); }                                                }                }        ){             Public voidrun () { while(true){                    Try{Thread.Sleep (500); } Catch(interruptedexception e) {e.printstacktrace (); } System.out.println ("Thread:" +Thread.CurrentThread (). GetName ());                    }}}.start (); }}


Review of traditional timer technology

Importjava.util.Date;ImportJava.util.Timer;ImportJava.util.TimerTask; Public classTraditionaltimertest {Private Static intCount = 0;  Public Static voidMain (string[] args) {/*new Timer (). Schedule (new TimerTask () {@Override public void run () {                            System.out.println ("bombing!"); }}, 10000,3000);*/                classMytimertaskextendstimertask{@Override Public voidRun () {count= (count+1)%2; System.out.println ("Bombing!"); NewTimer (). Schedule (/*New TimerTask () {@Override public void run () {                    System.out.println ("bombing!"); }                }*/NewMytimertask (), 2000+2000*count); }        }                NewTimer (). Schedule (NewMytimertask (), 2000);  while(true) {System.out.println (NewDate (). getseconds ()); Try{Thread.Sleep (1000); } Catch(interruptedexception e) {//TODO auto-generated Catch blockE.printstacktrace (); }        }    }}


Traditional thread Mutex technology
Traditional thread synchronous communication technology
Concept and function of shared variables in thread scope
Threadlocal Class and application skills
Discussion on how to share data among multiple threads
Application of Java5 Atomic operation class
Application of Java5 thread concurrency library
The application of callable and future
Thread Lock Technology for JAVA5
The magical technique of java5 reading and writing lock
Application of Java5 condition blocking condition
Java5 's Semaphere Sync Tool
Java5 's Cyclicbarrier Sync Tool
Java5 's Countdownlatch Sync Tool
JAVA5 's Exchanger Sync Tool
Application of Java5 blocking queue
Application of Java5 Synchronous collection class
Aerial network selection Intern's face question 1
Aerial network selection intern's face question 2
Aerial network selection intern's face question 3


How traditional threads are created

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.