java 线程操作
2012-04-06 16:20
323 查看
/** * * <b>Application name:</b><br> * <b>Application describing:</b> 通过继承Thread类,来创建自己的线程<br> */ class ExtendsThread extends Thread{ /** * * {重写父类中的run方法} * * @author:developer */ public void run(){ try{ while(true){ System.out.println(getName()+"正在运行."); Thread.sleep(1000); } }catch(InterruptedException e){ e.printStackTrace(); } } } /** * * <b>Application name:</b><br> * <b>Application describing:</b>通过实现Runnable接口,来创建自己的线程 <br> */ class RunableThread implements Runnable{ /** * * {实现父类中的方法} * * @author:developer */ public void run(){ try{ while(true){ System.out.println(Thread.currentThread().getName()+"正在运行."); Thread.sleep(1000); } }catch(InterruptedException e){ e.printStackTrace(); } } } /** * * <b>Application name:</b><br> * <b>Application describing:</b> 线程操作类<br> */ public class ThreadOperation { /** * * {方法功能中文描述} * * @param args */ public static void main(String[] args) { Thread thread1 = new ExtendsThread(); Thread thread2 = new Thread(new RunableThread()); thread1.start(); thread2.start(); } }
相关文章推荐
- Java 线程的基本状态和操作
- JAVA线程操作常见面试题 包括不使用内部类对多个线程加减1
- Java并发09:Thread的基本方法(6)-线程优先级priority相关说明与操作
- Java多线程总结(4)— 线程范围内数据操作的隔离及ThreadLocal类
- java线程学习1——线程基本概念和操作
- java 总结4种线程中操作UI界面的方法
- 线程基础:线程(2)——JAVA中的基本线程操作(上)
- Java线程安全队列操作
- 【Java线程篇】线程的基础操作(新建)
- Java ConcurrentLinkedQueue队列线程安全操作
- JAVA的线程操作
- Java常用高级线程操作
- java线程操作 sleep wait start wait 等
- JAVA线程操作SWT
- 【Java基础】线程笔记——原子操作:atomic
- 线程基础:线程(3)——JAVA中的基本线程操作(中)
- 操作集合的线程安全考虑——java
- JAVA中的多线程操作:线程等待、阻塞、让步
- java 线程操作
- JAVA中的多线程操作。线程等待、阻塞、让步,挂起 等