java-thread

来源:互联网 发布:淘宝哪家牛仔裤质量好 编辑:程序博客网 时间:2024/06/03 07:01
package com.pacoson.mythread;public class NumberRunnable implements Runnable {private int first;public NumberRunnable(int first) {this.first = first;}public NumberRunnable(){this(0);}public void run() {System.out.println();for (int i = first; i < 50; i += 2) {System.out.println(i + "  ");System.out.println("结束!");}}public static void main(String[] args) {NumberRunnable odd = new NumberRunnable(1);// 创建线程对象Thread thread_odd = new Thread(odd, "奇数线程");thread_odd.start(); // 启动线程对象new Thread(new NumberRunnable(2),"偶数线程").start();}}

0 0
原创粉丝点击