package com.thread;
/*
* jion可以临时加入一个线程,并且该线程运算完,其他线程继续运行。
* jion:当a线程执行到了b线程的.jion()方法是,a就会等b线程执行完
* 才会执行
* jion可以用来临时加入线程执行。
*
*
* yield暂停当前正在执行的线程对象,并执行其他线程
*
* */
public class Note1 implements Runnable {
public void run() {
for (int x = 0; x < 79; x++) {
System.out.println(Thread.currentThread().getName() + x);
Thread.yield();
}
}
}
class JoinDemo {
public static void main(String[] args) {
Note1 d = new Note1();
Thread t1=new Thread(d);
Thread t2=new Thread(d);
t1.start();
t1.setPriority(Thread.MAX_PRIORITY);
t2.start();
for (int x = 0; x < 80; x++) {
System.out.println("main....." + x);
}
System.out.println("over");
}
}
------------------------------------------------------------------
/*
* 一般开发写线程书写格式
*
* */
public class Note1 {
public static void main(String[] args) {
new Thread() {
public void run() {
for (int x = 0; x < 100; x++) {
System.out.println(Thread.currentThread().getName()
+ "......" + x);
}
}
}.start();
for (int x = 0; x < 100; x++) {
System.out.println(Thread.currentThread().getName() + "......" + x);
}
Runnable runnable=new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
for (int x = 0; x < 100; x++) {
System.out.println(Thread.currentThread().getName() + "......" + x);
}
}
};
new Thread(runnable).start();
}
}