摘要:如上图,红框中表示OjectMonitor的enter方法一进来就通过CAS将OjectMonitor的_owner设置为当前线程,绿框中表示设置成功的逻辑,第一个if表示重入锁的逻辑,第二个if表示第一次设置_owner成功,都意味着竞争锁成功,而我们的线程C显然是竞争失败的,会进入下图中的无线循
阅读全文
随笔分类 - 线程
摘要:此时的线程C无法进入synchronized{}代码块,用jstack看应该是BLOCKED状态,如下图: 我们看看monitorenter指令对应的源码吧,位置:openjdk/hotspot/src/share/vm/interpreter/interpreterRuntime.cpp 1 IR
阅读全文
摘要:1 void ATTR ObjectMonitor::exit(bool not_suspended, TRAPS) { 2 3 Thread * Self = THREAD ; 4 5 if (THREAD != _owner) { 6 7 if (THREAD->is_lock_owned((a
阅读全文
摘要:1 // Consider: 2 3 // If the lock is cool (cxq == null && succ == null) and we're on an MP system 4 5 // then instead of transferring a thread from th
阅读全文
摘要:1 // Wait/Notify/NotifyAll 2 3 // 4 5 // Note: a subset of changes to ObjectMonitor::wait() 6 7 // will need to be replicated in complete_exit above 8
阅读全文
摘要:总结: Thread类中的static boolean interrupted()修改中断状态为false ,boolean isInterrupted()只判断中断状态,但不修改 public void interrupt() 将调用者线程的中断状态设置为true; public boolean
阅读全文
摘要:1 package sun.nio.ch; 2 3 public abstract interface Interruptible 4 { 5 public abstract void interrupt(Thread paramThread); 6 } 1 /** 中断此线程。 2 * Inter
阅读全文
摘要:start0调用jvm的JVM_StartThread函数 调用run方法 总结: 1:JVM通过new JavaThread(&thread_entry, sz); 创建一个系统内核线程。 2:在内核线程的初始运行方法中,利用JavaCalls模块,调用java线程的run()方法,开始java级
阅读全文
摘要:/* What will be run. */ private Runnable target; 如果线程在创建时传入了Runnable运行对象,那么该对象的run方法将被调用 1 /** 2 * If this thread was constructed using a separate 3 * <code>Runnable</code> run object, then that 4 * <
阅读全文
摘要:总结: 1. 要通过thread来执行的类实例,并且不需要重写除了run()以外其它thread方法,则应使用runnable接口2. 实现runnable接口必须定义一个没有参数的run方法,run方法中可以做任何操作
阅读全文
摘要:1 默认构造方法 分配一个新的线程对象 2 这个构造器和上面的#Thread(ThreadGroup,Runnable,String)方法有相同作用,其中线程名是新生成的名称 3 自动生成名称的格式为Thread-n,其中n是一个整数 4 /** 5 * Allocates a new {@code Thread} object. This constructor has the same 6 *
阅读全文
摘要:初始化线程的核心方法 参数:ThreadGroup(线程组) Runnable
阅读全文
摘要:jdk方法定义 public static native void yield(); yield()方法的作用是 放弃当前的CPU资源,将它让给其它任务。但放弃的时间不确定。 | | jvm层实现 jvm_yield
阅读全文
浙公网安备 33010602011771号