为什么启动多个线程电脑会相当卡,而且在运行结束的时候不会自动停止。例如:- package com.Thread;
- public class Thread_Demo {
- public static void main(String[] args) {
- TessThread t = new TessThread();
- for (int i = 0; i < 4; i++) {
- new Thread(t).start();
- }
- }
- }
- class TessThread implements Runnable {
- private int tickets = 20;
- public void run() {
- while (true) {
- if (tickets > 0) {
- try {
- Thread.sleep(100);
- } catch (Exception e) {
- }
- System.out.println(Thread.currentThread().getName() + "出售票"
- + tickets--);
- }
- }
- }
- }
复制代码 |