⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 multithreaddemo.java

📁 一款少见的用swt写的彩票软件
💻 JAVA
字号:
package com.dc.test;

class MultiThreadDemo
{
    public static void main(String args[])
    {
        NamePrinter jacky = new NamePrinter("Jacky");
        NamePrinter mickel = new NamePrinter("Michel");
        NamePrinter jone = new NamePrinter("Jone");
        
        Thread thread1 = new Thread(jacky);
        Thread thread2 = new Thread(mickel);
        Thread thread3 = new Thread(jone);
        
        thread3.setPriority(Thread.MAX_PRIORITY);
        
        thread1.start();
        thread2.start();
        thread3.start();        
    }
}

class NamePrinter implements Runnable
{
    private String name;
    
    public NamePrinter(String name)
    {
        this.name = name;
    }
    public String getName()
    {
        return name;
    }
    public synchronized void run()
    {
        int i=0;
        while(i<5)
        {  
            System.out.println("\n\ni = "+    i++      +"  name = "+name);
            System.out.println("ThreadName = "+Thread.currentThread().getName());  //这两行输出
                                                         //为什么一个线程不能完整输出
            try
            {
                Thread.sleep(2000);
            }catch(InterruptedException e)  
            {
                
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -