java多线程编程pdf(JAVA编程多线程)

本文目录
JAVA编程多线程
继承java.lang.Thread类。
package com.cchongda.threadtest;
public class ThreadTest extends Thread{
public int i =10;
public void run(){ System.out.println("当前线程是:"+Thread.currentThread()); System.out.println("现在i的值为:"+i); try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } i = 15; System.out.println("修改后的i值为:"+i+Thread.currentThread()); }
public static void main(String args) {
ThreadTest tt1 = new ThreadTest(); ThreadTest tt2 = new ThreadTest(); tt1.start(); tt2.start(); }
} 这样就能实现创建了两个线程 并启动这两个线程去执行run()方法了,。
java如何实现多线程编程
1、public class MyThread extends Thread{//重写run()方法public void run(){ //多线程要做的事}public static void main(String args){ NThread nt = new NThread(); new Thread(nt,"nt1_name").start(); new Thread(nt,"nt2_name").start(); }}
java多线程编程
public class TestRunnable implements Runnable {
private int i ;
public void run() {
for( ; i 《 30; i++){
System.out.println(Thread.currentThread().getName()+ " " + i + "ok");
}
}
public static void main(String args) {
int i = 0;
for(; i 《 30; i++){
System.out.println(Thread.currentThread().getName() + " " + i);
if(i == 10){
TestRunnable tr = new TestRunnable();
new Thread(tr, "子线程0").start();
new Thread(tr, "子线程1").start();
}
}
}
}

更多文章:
directive vue(如何在Vue中建立全局引用或者全局命令)
2026年5月6日 19:15
javaeclipse包的新建(用eclipse如何创建java工程)
2026年1月11日 08:30
c语言switch语句case后面接什么(c语言switch语句中case后面必须要接整型常量和字符型常量吗)
2025年10月26日 08:15
怎么把普通文件导入变成web项目(java项目怎么转成web项目)
2025年9月18日 16:00
在循环体内使用break语句(在循环结构中使用break语句,退出的是一层循环,还是多重循环呢可以给出一个简单且巧妙的例子吗)
2026年5月1日 00:00
position在css的属性(CSS中position属性详解)
2025年9月26日 23:45
amazed是什么牌子(amazing和amazed有什么区别)
2026年4月3日 15:00
周期函数值域的求法(已知函数的最小正周期为求;当时,求函数的值域.)
2025年11月30日 22:15
毕设做网站必须要用到ssm框架嘛(毕业设计做ssm还是app更难)
2026年3月31日 03:00
new directory(如何将威纶通tk6070ip触摸屏程序上传到电脑里)
2026年8月7日 01:45













