1. 当线程处于Blocked状态(sleep,wait,join),线程会退出阻塞状态,并抛出一个InterruptedException.park除外,它有响应但是不会抛出异常 2. 当线程处于Running状态,只是线程的interrupt标记被设置为true,线程本身的运行不会受到任何影响. 上面说得其实还不是特别准确,Java 1.8的Thread.interrupt()方法的注释如下,这个应该是最为权威准确的 Unless the current thread is interrup…
从原理上讲其实Thread.yeild方法其实只是给线程调度机制一个暗示:我的任务处理的差不多了,可以让给相同优先级的线程CPU资源了:不过确实只是一个暗示,没有任何机制保证它的建议将被采纳: 看一个例子就知道了: public class LiftOff implements Runnable { protected int countDown = 5; private static int taskCount = 0; private final int id = taskCount++;…
Thread.run方法是同步方法, 线程: package com.stono.thread.page005; public class MyThread extends Thread { @Override public void run() { super.run(); System.out.println("MyThread"); } } 调用: package com.stono.thread.page005; public class Run { public static…
thread.Join把指定的线程加入到当前线程,可以将两个交替执行的线程合并为顺序执行的线程.比如在线程B中调用了线程A的Join()方法,直到线程A执行完毕后,才会继续执行线程B.t.join(); //使调用线程 t 在此之前执行完毕.t.join(1000); //等待 t 线程,等待时间是1000毫秒 先上一段JDK中代码: /** * Waits at most <code>millis</code> milliseconds for this threa…
概念 我们知道 start() 方法是启动线程,让线程变成就绪状态等待 CPU 调度后执行. 那 yield() 方法是干什么用的呢?来看下源码. /** * A hint to the scheduler that the current thread is willing to yield * its current use of a processor. The scheduler is free to ignore this * hint. * * <p> Yield is a heu…
一.字符串类型(str) class str(basestring): """ str(object='') -> string Return a nice string representation of the object. If the argument is a string, the return value is the same object. """ def capitalize(self): ""&q…
结论:A 线程调用 B 线程对象的 join 方法,则 A 线程会被阻塞,直到 B 线程 挂掉 (Java Doc 原话: Watis for this thread to die). 一.分析 查看源代码: public final void join() throws InterruptedException { join(0); //得接着看这个带参数的方法,这里传入 0 表示等待时间为永久 } 带参数的 join: public final synchronized void join(…
join()的作用:Waits for this thread to die.等待线程对象销毁.在Thread源码中可以看到join源码是使用了wait()方法来实现等待功能. 因为join()内部使用了wait()方法实现,wait方法被调用后线程会释放锁,因此join方法也具有释放锁的特点. 这也是join().wait()和sleep()的区别,sleep是不会释放锁的. JDK1.8中join源码如下: public final synchronized void join(long m…
API文档charAt(int index)是这样定义的: charAt(char index):Returns the char value at the specified index.在指定的索引返回字符的值: 示例 使用charAt函数获取字符串strCom中索引值为4的char值,并将结果赋值给int变量strLower: String strCom = "I like you"; int strLower = strCo…