Java 并发 --线程基本概念
线程的基本概念
线程是条单独的执行流,有自己的栈,和程序技术器
一般创建线程的方法有:
- 继承Thread
- 实现Runnable
- 实现Callable
线程的基本属性和方法
1. id和name
id是一个自增的id,每新建一个线程就+1
private static synchronized long nextThreadID() {
return ++threadSeqNumber;
}
name 是Thread后面跟一串数字
public Thread() {
init(null, null, "Thread-" + nextThreadNum(), 0);
}
2. 线程的优先级
线程的优先级是 1-10 默认是5
这个优先级的概念最终会被映射成操作系统的优先级,当然并不是10个优先级都能映射
/**
* The minim