线程

Thread
1 、继承自Runnable
2 、六种状态:
new :The thread has been created, but has never been started.
rrunnable: The thread may be run.
Block: The thread is blocked and waiting for a lock.
waiting The thread is waiting.
Timed_waiting The thread is waiting for a specified amount of time.
Terminated : The thread has been terminated.
优先级别分为 1-10,5 为正常

多线程

ExecutorService 线程池。理解:相当于一个正在不断运转的引擎。里面的线程都是处于活动状态,等待任务的加入。

newCachedThreadPool():缓存型。如果有建立过的线程,并且这个线程没有timeout(线程在线程池里有生命周期,超出时间就会被回收),就会重复利用这个线程。所以一般适用于线程的任务短小,但会频繁使用的情况。

newFixedThreadPool:任意一个时间点,只能有固定数量的线程在活动,

ScheduledThreadPool:
SingleThreadExecutor:任意时间点,池中只有一个线程。

private static Test mInstance;
private static ExecutorService cache = Executors.newCachedThreadPool();
private static ExecutorService fix = Executors.newFixedThreadPool(5);
private static ExecutorService schedule = Executors.newScheduledThreadPool(5);
private static ExecutorService single = Executors.newSingleThreadExecutor();
public static void main(String[] args)
{
// TODO Auto-generated method stub
cache .execute( mInstance);
fix .execute( mInstance);
schedule .execute( mInstance);
single .execute( mInstance);
}