1. Threading method
1), Start (), start the thread, and go to the ready state, ready for execution
2), run (), overriding method, starting execution thread
3), CurrentThread (), calling the current thread
4), GetName (), get the thread name
5), SetName (), set the thread name
6), yield (), call this method of the thread, release the current CPU execution, CPU execution other threads, object lock will not release
7), join (), call the Join method of the B thread in a thread, a thread pauses execution, executes the b thread until the B thread finishes executing,
A thread continues execution after the join () method is followed by the code.
8), isAlive (), whether the thread survives
9), Sleep (l), so that the current thread sleeps l milliseconds.
10), Wait (), notify (), Notifyall ()
Packagecom.thread.test;classThread1extendsthread{@Override Public voidrun () {thread.currentthread (); System.out.println (Thread.CurrentThread (). GetName ()); for(inti = 1; I <=100; i++) {System.out.println (Thread.CurrentThread (). GetName ()+"===="+i); } }}/*** Thread Main method * 1, start (), start thread, and go into ready state, wait for execution * 2, run (), override method, start thread * 3, CurrentThread (), call current thread * 4, GetName () , get the thread name * 5, SetName (), set the thread name * 6, yield (), call this method of the thread, release the current CPU execution, the CPU executes other threads, the object lock will not release * 7, join (), call the B thread's join method in a thread, a thread Pause execution, execute the b thread until the B thread finishes executing, and the code after the join () method continues execution. * 8, IsAlive (), whether the thread survives * 9, sleep (l), so that the current thread sleeps l milliseconds. */ Public classtestthread{ Public Static voidMain (string[] args) {thread.currentthread (). SetName ("Main Thread"); Thread1 T1=NewThread1 (); T1.setname ("Sub-thread 1"); T1.start (); for(inti = 1; i<= 100; i++) {System.out.println (Thread.CurrentThread (). GetName ()+"......"+i); if(i% 10 = = 0) {thread.currentthread (); Thread.yield ();//Release Current CPU } if(i = = 20) {Thread1 t2=NewThread1 (); T2.setname ("Sub-thread 2"); Try{t2.join (); } Catch(interruptedexception e) {e.printstacktrace (); } } } }}
2. Thread Priority
Thread scheduling
(1) Time slice strategy, with priority thread, composed of FIFO queue, using time slice strategy
(2) Preemptive strategy, high priority first execution
Thread 1-Thread common methods