(黑马Java多线程与并发库高级应用)01 传统线程技术回顾
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了(黑马Java多线程与并发库高级应用)01 传统线程技术回顾相关的知识,希望对你有一定的参考价值。
传统创建线程的两种方式
package cn.itcast.heima2; public class TraditionalThread { public static void main(String[] args) { // TODO Auto-generated method stub Thread thread = new Thread() { @Override public void run() { while (true) { try { Thread.sleep(500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(Thread.currentThread().getName()); System.out.println(this.getName()); } } }; thread.start(); Thread thread2 = new Thread(new Runnable() { @Override public void run() { while (true) { try { Thread.sleep(500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(Thread.currentThread().getName()); } } }); thread2.start();//更可以体现面向对象的思想,线程和代码隔离 new Thread(new Runnable() { @Override public void run() { while (true) { try { Thread.sleep(500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("runnable:"+Thread.currentThread().getName()); } } }){ @Override public void run() { while (true) { try { Thread.sleep(500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("thread:"+Thread.currentThread().getName()); } } }.start(); } }
以上是关于(黑马Java多线程与并发库高级应用)01 传统线程技术回顾的主要内容,如果未能解决你的问题,请参考以下文章
(黑马Java多线程与并发库高级应用)02 传统定时器技术回顾