首页 > 代码库 > Java 多线程
Java 多线程
package com.lf.threadhomework; public class TestHomework { public static void main(String[] args) { // 打印奇数的线程 OddNumberThread oddNumberThread = new OddNumberThread(); oddNumberThread.start(); // 打印0~100的线程 NumberThread numberThread = new NumberThread("打印0~100的线程"); numberThread.start(); //打印偶数的线程 EvenNumberThread evenNumberThread = new EvenNumberThread(); Thread thread = new Thread(evenNumberThread); thread.start(); } } class OddNumberThread extends Thread{ @Override public void run() { for (int i = 0; i < 100; i++) { if (i%2==1) { System.out.println("打印0~100之间的奇数:"+i); } } } public OddNumberThread(){ super(); } } class NumberThread extends Thread{ public String threadName; public NumberThread(String name) { // TODO Auto-generated constructor stub threadName = name; } @Override public void run() { // TODO Auto-generated method stub for (int i = 0; i < 100; i++) { System.out.println(threadName+i); } } } class EvenNumberThread implements Runnable{ @Override public void run() { // TODO Auto-generated method stub for (int i = 0; i < 100; i++) { if (i%2==0) { System.out.println("打印0~100之间的偶数:"+i); } } } }
Java 多线程
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。