zoukankan      html  css  js  c++  java
  • 线程中的Thread类中的方法

    /**
    * 线程中常用的方法
    * 1.start():启动线程,运行run()方法
    * 2.run():是Thread类重写的方法,将线程需要执行的操作写在此方法中、
    * 3.currentThread():返回当前线程
    * 4.setName():设置线程名
    * 5.getName():获取线程名
    * 6.yield():线程礼让
    * 7.join():线程抢占
    * 8.stop():强制结束线程
    * 9.sleep(时间):睡眠
    * 参数
    * MAX_PRIORITY:10
    * MIN_PRIORITY:1
    * NORM__PRIORITY:5 默认
    *
    * 设置与获取线程的优先级
    * setPriority(XXX_PRIORITY)
    * getPriority()
    * @Author: ITYW
    * @Create 2020 - 10 - 25 - 22:00
    */
    public class ThreadMethod {
    public static void main(String[] args) {
    MyThread myThread = new MyThread();
    myThread.setName("MyThread");
    Thread.currentThread().setName("main");
    /* myThread.setPriority(Thread.MAX_PRIORITY);
    Thread.currentThread().setPriority(Thread.MIN_PRIORITY);*/
    myThread.start();

    for (int i = 0; i <= 10000; i++) {
    /* try {
    Thread.sleep(100);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }*/
    System.out.println(Thread.currentThread().getName()+"main"+i);
    /*if (i == 10){
    try {
    myThread.join();
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    }*/
    }
    }
    }
    class MyThread extends Thread{

    @Override
    public void run() {
    for (int i = 0; i <= 1000; i++) {
    /* try {
    sleep(100);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }*/
    System.out.println(Thread.currentThread().getName()+"MyThread"+i);
    if (i %10==0){
    yield();
    }
    }
    }
    }
  • 相关阅读:
    animate动画回调函数
    triggerHandler不执行事件默认值
    trigger自动执行事件
    js与jquery对象的互转
    让低版本浏览器支持html5的标签
    闭包的好处罗列
    AJAX跨域
    php能干什么?
    concat() 方法用于连接两个或多个数组。
    使用 v-cloak 防止页面加载时出现 vuejs 的变量名
  • 原文地址:https://www.cnblogs.com/ITYW/p/13875928.html
Copyright © 2011-2022 走看看