Java多线程之知识点

1. Parallelism≠Concurrency, concurrency can occur on a single processor, parallelism require more than one processor.

2. Properites of concurrent system: safety (nothing bad will ever happen) and liveness (something good eventually happens).

3. Java calls a process a "thread"

4. Thread states: (created)->runnable, non-runnable, running->(dead).

5. Java thread primitives: start(), run(), sleep(), stop(), interrupt(), isAlive(), join(), yield(), wait(), setPriority()[1-10]...

6. join() method suspends the execution of the calling thread until the object called finishees its excution, 通常用在main中,等待其他线程完成后再继续main()的程序。

7. thread.sleep()可以休眠线程,例如thread.sleep(1000)可以休眠线程1秒,但是可以被thread.interrupt()打断。

8. thread.setPriority() 可以设置线程优先级,主线程优先级为5,然而并非优先级高就可以先执行,仍旧取决于CPU资源分配。

9. thread.yield()可以让线程暂停,从running状态变为runnable状态,能让通优先级的thread有执行机会,但具体哪个线程执行取决于CPU。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值