zoukankan      html  css  js  c++  java
  • 【Java】Java多线程

    线程相关概念

    • 一个进程至少有一个线程
    • 在Java中,一个进程至少有两个线程,一个是main线程,一个是垃圾回收线程
    • 守护线程:JVM会在只剩下守护线程的时候结束,也就是说所有非守护线程结束,JVM就会结束
      - 典型例子:main线程(非守护线程,不能设置成守护线程),垃圾回收线程(守护线程)
    • 线程的状态:NEW、RUNNABLE、BLOCKED、WAITING、TIMED_WAITING、TERMINATED
    • 线程优先级:[1,10]. 优先级越高不代表一定优先于优先级低的线程执行,而是会比低的得到更多的CPU资源
    • 打印线程的相关信息
            System.out.println("getName: "+Thread.currentThread().getName());
            System.out.println("getContextClassLoader: "+Thread.currentThread().getContextClassLoader());
            System.out.println("getId: "+Thread.currentThread().getId());
            System.out.println("getPriority: "+Thread.currentThread().getPriority());
            System.out.println("getStackTrace: "+Thread.currentThread().getStackTrace());
            System.out.println("getState: "+Thread.currentThread().getState());
            System.out.println("getThreadGroup: "+Thread.currentThread().getThreadGroup());
            System.out.println("getUncaughtExceptionHandler: "+Thread.currentThread().getUncaughtExceptionHandler());
            System.out.println("getClass: "+Thread.currentThread().getClass());
            System.out.println("toString: "+Thread.currentThread().toString());
            System.out.println("isAlive: "+Thread.currentThread().isAlive());
            System.out.println("isDaemon: "+Thread.currentThread().isDaemon());
            System.out.println("isInterrupted: "+Thread.currentThread().isInterrupted());
            System.out.println("Thread: "+Thread.currentThread());
    

    创建线程的四种方式

    • 继承Thread
    • Runnable
    • Callable
    • 线程池
  • 相关阅读:
    支持向量机SVM知识点概括
    决策树知识点概括
    HDU 3081 Marriage Match II
    HDU 3572 Task Schedule
    HDU 4888 Redraw Beautiful Drawings
    Poj 2728 Desert King
    HDU 3926 Hand in Hand
    HDU 1598 find the most comfortable road
    HDU 4393 Throw nails
    POJ 1486 Sorting Slides
  • 原文地址:https://www.cnblogs.com/0nePlece/p/15068180.html
Copyright © 2011-2022 走看看