参考博客: https://blog.csdn.net/guangyinglanshan/article/details/51645053 公司项目近段时间要使用thread, 个人想去了解Thread.sleep和Thread.currentYhread.sleep的不同之处,在这里做一下简单的记录. 一.第一种方式是只调用sleep静态方法:第二种是获取对象后再调用sleep静态方法.第二种方式效率要低一些,因为多了一次函数调用, 而且通过对象调用静态方法也不太符合“静态”的定义(静态成员最…
JAVA线程状态.线程START方法源码.多线程.JAVA线程池.如何停止一个线程等多线程问题 这两个方法有点容易记混,这里就记录一下源码. Thread.interrupted()和Thread.currentThread().isInterrupted()区别 静态方法Thread.interrupted()源码如下: public static boolean interrupted() { return currentThread().isInterrupted(true); } 可以看…
先看一下代码 public class Thread1 extends Thread{ @Override public void run() { try { System.out.println("Start"); //Thread.sleep(5000); Thread.currentThread().sleep(5000); System.out.println("Finished"); } catch (InterruptedException e) { /…
package com.citi.tm.api.trade.mongo; public class ThreadTest { public static void main(String[] args) { Runnable r = () -> { try { //Thread.currentThread().sleep(15000);//a, b, sleep Thread.sleep(15000);//a, b, sleep } catch (InterruptedException e)…
Thread thread2 = new Thread() { @Override public void run() { test.function(); } }; thread1.start(); thread2.start(); } } class TestCase { public synchronized void function() {// add synchronized keyword. for (int i = 0; i < 5; i++) { System.out.prin…
Thread 有6个状态 , NEW, RUNNABLE , BLOCKED, WATTING, TIMED WAITING, TERMINATED 1.NEW至今尚未启动的线程的状态.2.RUNNABLE可运行线程的线程状态.处于可运行状态的某一线程正在 Java 虚拟机中运行,但它可能正在等待操作系统中的其他资源,比如处理器.3.BLOCKED受阻塞并且正在等待监视器锁的某一线程的线程状态.处于受阻塞状态的某一线程正在等待监视器锁,以便进入一个同步的块/方法,或者在调用 Object.wai…
一.join用法 join()和wait()不会释放锁,join()是Thread的方法,wait()是Object的方法 1.join方法定义在Thread类中,则调用者必须是一个线程 例如: Thread t = new CustomThread();//这里一般是自定义的线程类 t.start();//线程起动 t.join();//此处会抛出InterruptedException异常 2.上面的两行代码也是在一个线程里面执行的 以上出现了两个线程,一个是我们自定义的线程类,我们实现了r…
线程这一概念,可以理解成进程中的一个小单元.这个单元是一个独立的执行单元,但是与进程中的其他线程共享进程中的内存单元. 由于Cpu资源是有限的,所以进程中的多个线程要抢占Cpu,这也导致进程中的多个线程交替执行. Thread.Sleep() 本身的含义是当前线程挂起一定时间. Thread.Sleep(0) MSDN上的解释是挂起此线程能使其他等待线程执行.这样的解释容易导致误解,我们可以这样理解,其实是让当前线程挂起,使得其他线程可以和当前线程再次的抢占Cpu资源. 代码示例: static…
链接:http://www.cnblogs.com/neve/articles/1863853.html 想更新个PHP的版本,PHP的windows版本已经分离出来了,见http://windows.php.net/download/,但是上面有很多不同的版本,包括VC9, VC6,  x86 Non Thread Safe, x86 Thread Safe, 好像没有x64版本的,(现在特别喜欢用64位的软件),版本有点多,主要的区别和如何选择不同的版本如下: If you are usin…
Thread.Join & Thread.IsAlive functions Join blocks the current thread and makes it wait until the thread on which Join method is invoked completes.Join method also has a overload where we can specify the timeout. If we don't specify the timeout the c…