Java--线程的创建方式(2)
2016-05-15 12:36
471 查看
public class MyRun implements Runnable{//可以实现多个接口 private int first; public MyRun(int first) { this.first = first; } public void run() { for(int i=first;i<=100;i+=2){ System.out.print(i+" "); } System.out.println(); } }
public class MyThread { public static void main(String[] args) { Thread t1=new Thread(new MyRun(1)); t1.start(); Thread t2=new Thread(new MyRun(2)); t2.start(); for(int i=101;i<=200;i++){ System.out.print(i+" "); } System.out.println(); } }
具体使用那种根据是否与多继承冲突
相关文章推荐
- Intellij Idea系列之JavaSE项目的创建(一)
- (三)JAVA使用POI操作excel
- 探讨Java验证码制作(上篇)
- 单例模式
- 浅析java中stringBuilder的用法
- spring配置-bean部分
- Java--线程的创建方式(1)
- 关于java.lang.reflect.InvocationTargetException
- eclipse到Android Studio的项目迁移
- 从最基本的Java工程搭建SpringMVC+SpringDataJPA+Hibernate
- JAVA连接MYSQL测试
- Maven基本配置
- java 生成xml文件
- Java字符串的比较是否相同
- eclipse代码自动补全的设置
- SpringMVC项目中中文字符乱码问题及解决办法总结(非专业最优解决办法) -- ajax传值乱码; request.getParameter()乱码;
- Java片段 Java中Double和Long互相转换
- java 线程池执行 callable 接口,future 接收callable 接口的返回值
- Spring实战-使用表达式装配(三)
- jdk7新特性一