Runnable创建线程 public class RunnableDemo implements Runnable{ @Override public void run(){ int i = 1; while(true) { System.out.println(Thread.currentThread().getName()+"线程名字"+i); i++; if(i>30){ break; } try{ Thread.currentThread().sleep(3000);
http://www.cppblog.com/prayer/archive/2012/04/23/172427.html 这两天在看Pthread 资料的时候,无意中看到这样一句话(man pthread_detach): Either pthread_join(3) or pthread_detach() should be called for each thread that an application creates, so that system resources for the
有些时候面试官经常会问,两个线程怎么交替执行呀,如果是三个线程,又怎么交替执行呀,这种问题一般人还真不一定能回答上来.多线程这块如果理解的不好,学起来是很吃力的,更别说面试了.下面我们就来剖析一下怎么实现多个线程顺序输出. 两个线程循环交替打印 //首先我们来看一种比较简单的方式 public class ThreadCq { public static void main(String[] args) { Stack<Integer> stack = new Stack<>();