一、进程与线程
进程是资源分配的最小单位,一个程序就是一个进程。
线程是进程中执行运算的最小单位。
二、线程的创建
三、线程实例变量的共享与synchronized
public class ThreadTest3App {
public static void main(String[] args) {
Thread[] threads = new Thread[5];
MyRunnal myRunnal = new MyRunnal();
for(int i = 1 ; i<=5;i++){
Thread sThread = new Thread(myRunnal,"s"+i);
threads[i-1] = sThread;
}
for(Thread t:threads){
t.start();
}
}
}
class MyRunnal implements Runnable{
private int count =5;
@Override
public synchronized void run() {
count--;
System.out.println(Thread.currentThread().getName() +":"+count);
}
}