架构师成长之旅第一篇

架构师成长之旅第一篇

日常积累

线程的状态:

状态解释
NEW新建状态,尚未启动状态
RUNNABLE就绪状态 正在运行或者是排队等待CPU给它分配资源
BLOCKED阻塞等待锁的状态,等待监视器锁,比如等待执行synchronized代码块或者使用synchronized标记的方法
WAITING等待状态,正在等待另一个线程执行某个特定的动作,比如调用了Object.wait()方法,等待另一个线程调用Object.notify()或者notifyAll()方法
TIMED_WAITING计时等待状态 比如调用了Object.wait(long timeout)和Thread.join(long timeout)等这些方法时,它才会进入此状态
TERMINATED终止状态,执行完毕

线程状态源代码如下:

public enum State{
		NEW,RUNNABLE,BLOCKED,WAITING,TIMED_WAITING,TERMINATED,
}

线程工作模式

Runnable的run方法和Thread的start方法区别
  1. run方法只是Runnable接口的一个普通方法可以执行多次,需要调用类重写此方法,执行此方法就是执行业务
  2. start方法是Thread类的线程安全的启动方法,只能执行一次
public synchronized void start() {
        /**
         * This method is not invoked for the main method thread or "system"
         * group threads created/set up by the VM. Any new functionality added
         * to this method in the future may have to also be added to the VM.
         *
         * A zero status value corresponds to state "NEW".
         */
        if (threadStatus != 0)
            throw new IllegalThreadStateException();

        /* Notify the group that this thread is about to be started
         * so that it can be added to the group's list of threads
         * and the group's unstarted count can be decremented. */
        group.add(this);

        boolean started = false;
        try {
            start0();
            started = true;
        } finally {
            try {
                if (!started) {
                    group.threadStartFailed(this);
                }
            } catch (Throwable ignore) {
                /* do nothing. If start0 threw a Throwable then
                  it will be passed up the call stack */
            }
        }
    }
线程的优先级
/**
  * The minimum priority that a thread can have.
  */
 public final static int MIN_PRIORITY = 1;

/**
  * The default priority that is assigned to a thread.
  */
 public final static int NORM_PRIORITY = 5;

 /**
  * The maximum priority that a thread can have.
  */
 public final static int MAX_PRIORITY = 10;
明日计划 idea导入mybatis源码开始源码之旅。。。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值