学习笔记——JAVA线程<7>线程的总结

xiaoxiao2021-02-28  90

一,创建线程 1,继承Thread 2,实现Runna类 3,实现Callable 二,线程的状态 1,新生–>start–>就绪–>运行–>阻塞–>终止 2,终止线程的方法 3,阻塞的方法join yield sleep 线程状态图解释 一条正常的线:New->Runble->Scheduler->Running->run()||completes->Dead 一条经过阻塞的线:New->Runble->Scheduler->Running->sleep()||join()->OtherwlseBlocked->sleep()timeout||thread join()->interupt()->RunnableRunning->run()||completes->Dead 一条经过同步的线:New->Runble->Scheduler->Running->synchronized()->Blocked in object’s lock pool->Runnable->Scheduler->Running->run()||completes->Dead 一条经过防止死锁的线: New->Runble->Scheduler->Running->Block in Object’s wait()pool->notify()||interupt()->Runable->Running->run()||completes->Dead 三,线程的信息 1,Thread。currentThread 2,获取名称 设置名称 设置优先级 四,同步对同一份资源 synchronized(引用类型变量|this|类.class){ } 修饰符 synchronized 方法的签名{ 方法体 } 过多的同步可能造成死锁 五,生产者消费者模式 信号灯方法 六,任务的调用 七,拓展 juc,quartz

转载请注明原文地址: https://www.6miu.com/read-21240.html

最新回复(0)