一,创建线程
1,继承Thread
2,实现Runna类
3,实现Callable
二,线程的状态
1,新生–>start–>就绪–>运行–>阻塞–>终止
2,终止线程的方法
3,阻塞的方法join yield sleep
学习笔记——JAVA线程<7>线程的总结
线程状态图解释
一条正常的线: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

相关文章:

  • 2021-11-28
  • 2021-11-28
  • 2021-05-11
  • 2022-12-23
  • 2021-07-08
猜你喜欢
  • 2021-05-10
  • 2021-10-08
  • 2021-06-12
  • 2021-11-23
  • 2021-08-09
  • 2022-01-14
  • 2022-02-03
相关资源
相似解决方案