0
点赞
收藏
分享

微信扫一扫

111.Thread,setPriority()

江南北 2022-04-26 阅读 47
package com.itheima.threaddemo7;

import java.util.concurrent.FutureTask;

public class Demo {
    public static void main(String[] args) {
        MyCallable mc=new MyCallable();
        FutureTask<String> tf=new FutureTask<>(mc);
        Thread t1=new Thread(tf);
        t1.setName("飞机");
        t1.setPriority(10);
        System.out.println(t1.getPriority());
        t1.start();

        MyCallable mc2=new MyCallable();
        FutureTask<String> tf2=new FutureTask<>(mc2);
        Thread t2=new Thread(tf2);
        t2.setName("坦克");
        t2.setPriority(1);
        System.out.println(t2.getPriority());
        t2.start();
    }
}
package com.itheima.threaddemo7;

import java.util.concurrent.Callable;

public class MyCallable implements Callable<String> {

    @Override
    public String call() throws Exception {
        for (int i = 0; i < 100; i++) {
            System.out.println(Thread.currentThread().getName()+"---"+i);
        }
        return "线程执行完毕了";
    }
}
举报

相关推荐

111

函数111

测试111

测试文章111

种芒果111

leetcodebfs-111

静态综合111

Codeforces 111 B

0 条评论