zoukankan      html  css  js  c++  java
  • 多线程1

    1.

     1 public class MyThread extends Thread{
     2     private  int count = 5;
     3     
     4     @Override
     5     public synchronized void run() {
     6         count--;
     7         System.out.println(Thread.currentThread().getName() + ":count="+count);
     8     }
     9 
    10     public static void main(String[] args) {
    11         /*MyThread t1 = new MyThread();
    12         MyThread t2 = new MyThread();
    13         MyThread t3= new MyThread();
    14         MyThread t4 = new MyThread();
    15         MyThread t5 = new MyThread();
    16         t1.start();
    17         t2.start();
    18         t3.start();
    19         t4.start();
    20         t5.start();
    21         结果:
    22                 Thread-4:count=4
    23                 Thread-1:count=4
    24                 Thread-2:count=4
    25                 Thread-3:count=4
    26                 Thread-5:count=4 */
    27         
    28         MyThread myThread = new MyThread();
    29         Thread t1 = new Thread(myThread, "t1");
    30         Thread t2 = new Thread(myThread, "t2");
    31         Thread t3 = new Thread(myThread, "t3");
    32         Thread t4 = new Thread(myThread, "t4");
    33         Thread t5 = new Thread(myThread, "t5");
    34         t1.start();
    35         t2.start();
    36         t3.start();
    37         t4.start();
    38         t5.start();
    39         /*
    40             t1:count=4
    41             t4:count=3
    42             t2:count=2
    43             t3:count=1
    44             t5:count=0    
    45          */
    46     }
    47 }
    View Code
  • 相关阅读:
    螺旋折线——第九届蓝桥杯C语言B组(省赛)第七题
    组合问题
    八皇后
    01背包(详解)
    最长递增子序列
    棋盘游戏
    The Accomodation of Students
    P3157 [CQOI2011]动态逆序对
    Building a Space Station
    焚风现象(差分模板题)
  • 原文地址:https://www.cnblogs.com/bravolove/p/7944187.html
Copyright © 2011-2022 走看看