博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java多线程-笔试题
阅读量:2444 次
发布时间:2019-05-10

本文共 904 字,大约阅读时间需要 3 分钟。

 1、多线程按规定顺序输出

package test;import java.util.HashSet;import java.util.Set;public class Main12 {    public static void main(String[] args) {        String[] strs={"_A","_B","_C"};        Thread pre=Thread.currentThread();        for(int i=0;i<3;i++){           Thread thread=new Thread(new Domio(strs[i],pre));           thread.start();           pre=thread;        }        System.out.print("begin");    }    static class Domio implements Runnable{        private String str;        private Thread thread;        public Domio(String str,Thread thread){            this.str=str;            this.thread=thread;        }        @Override        public void run() {            String string=this.str;            try {                this.thread.join();            } catch (InterruptedException e) {                e.printStackTrace();            }            System.out.print(str);        }    }}输出:begin_A_B_C

 

转载地址:http://zgpqb.baihongyu.com/

你可能感兴趣的文章
ipad iphone开发_如何在iPhone或iPad上的消息中快速选择表情符号
查看>>
如何在iPhone和iPad上使用操作和共享扩展
查看>>
windows 网络唤醒_如何停止唤醒Windows PC的网络活动
查看>>
社交网站facebook_如何退出Facebook,Twitter,Google +和其他社交网络
查看>>
windows 所有者窗口_如何在任何版本的Windows中更改注册的PC所有者
查看>>
使用Prime提前一周观看新的Aquaman电影,方法如下
查看>>
为什么uber有星级_位智拼车和Uber / Lyft有什么区别?
查看>>
所需的密钥从密钥环中丢失_如果丢失U2F密钥该怎么办
查看>>
如何在Windows 10的设置中禁用建议横幅
查看>>
Pixel 3 XL上的开发人员选项将使您“隐藏”缺口
查看>>
kde gnome_KDE Apps如何在GNOME下运行?
查看>>
启动磁盘10.11.4_如何在Windows 8.1中检查应用程序的磁盘使用情况
查看>>
如何制作优质的YouTube视频
查看>>
如何在Windows 10的照片中启用暗模式
查看>>
新的Apple Watch面Kong即将到来,这就是它们的外观
查看>>
怎么打开avi文件文件损坏_什么是AVI文件(以及如何打开一个文件)?
查看>>
chrome恢复翻译选项_使用此隐藏选项使Chrome再次看起来正常
查看>>
python包的obo文件_出售:1976苹果1.仍然有效,要价$ 300,000 OBO
查看>>
技嘉主板控制机箱风扇_在机箱外为主板加电是否安全?
查看>>
bittorrent_最好的免费BitTorrent客户
查看>>