java多线程系列(一):Thread、Runnable、Callable实现多线程的区别

java学习线程篇之多线程的实现方式:继承Thread类、实现Runnable接口或Callable接口~ java学习之线程篇~1. 基本概念:进程与线程2. 实现多线程的方式2.1 继承Thread类 1. 基本概念:进程与线程 在操作系统的定义中,进程是指一次程序的完整运行,这个运行的过程之中内存、处理器、IO等资源操作都要为这个进程进行服务。 Windows属于多进程的操作系统,那么问题就来了?每一个进程都需要资源的支持,那么这么多进程怎么分配资源呢? 在同一个时间段上,会有多进程轮流去抢占资源... 阅读详情

创建线程的三种方法

java实现多线程的方法有三种,分别是继承thread类,实现runnable接口,实现callable接口

下面是三种实现方式的简单例子,请观察一下

/**
 * 继承Thread
 */
public class MyThread extends Thread{
     int a = 0;
    @Override
    public void run() {
        //线程的核心实现
        synchronized (this){
            try {
                sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println( ++a );
        }

    }
}

class MyThreadTest{
    public static void main(String[] args) {
        //实例三个线程
        MyThread myThread1 = new MyThread();
        MyThread myThread2 = new MyThread();
        MyThread myThread3 = new MyThread();

        //启动三个线程
        myThread1.start();
        myThread2.start();
        myThread3.start();
        
    }
}

输出结果:

/**
 * 实现Runnable接口
 */
public class MyRunnable implements Runnable {
    int a = 0;

    @Override
    public void run() {
        //线程核心处理方法
        System.out.println(++a);
    }

}

class MyRunnableTest {
    public static void main(String[] args) {
        //实例话MyRunnable
        Runnable runnable = new MyRunnable();

        //通过runnable实例化三个线程
        Thread thread1 = new Thread(runnable);
        Thread thread2 = new Thread(runnable);
        Thread thread3 = new Thread(runnable);

        //启动三个线程
        thread1.start();
        thread2.start();
        thread3.start();

        // 输出的结果为1  2  3  ,输出的顺序可能不同

    }
}

输出结果:

/**
 *
 * 实现Callable接口
 */
public class MyCallable implements Callable<String> {

    int a = 0;

    @Override
    public String call() throws Exception {
        ++a;
        System.out.println(Thread.currentThread().getName() + ",a=" + a);
        return String.valueOf(a);
    }
}

class TestCallable {

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        Callable callable = new MyCallable();
        FutureTask<String> task = new FutureTask<String>(callable);


        Thread thread1 = new Thread(task,"线程一");
        Thread thread2 = new Thread(task,"线程二");
        Thread thread3 = new Thread(task,"线程三");

        thread1.start();
        thread2.start();
        thread3.start();
        // 取得返回值
        System.out.println(task.get());
        
    }
}

输出结果:




Thread、Runnable、Callable接口实现多线程的区别

观察以上三种实现方式和输出的结果可得
1.继承Thread方式,每次new Thread都是独立的,资源不共享,而Runnable资源共享;
2.实现Callable接口方式,只能运行一次FutureTask

Thread类与Runnable接口实现多线程的区别

1.Thread类是Runnable接口的子类,使用runnable接口实现多线程可以避免单继承局限;

2.Runnable接口实现的多线程可以比Thread类实现的多线程更加清楚的描述数据共享的概念。

如何理解:
因为一个线程只能启动一次,通过Thread实现线程时,线程和线程所要执行的任务是捆绑在一起的。也就使得一个任务只能启动一个线程,不同的线程执行的任务是不相同的,所以没有必要,也不能让两个线程共享彼此任务中的资源。

通过Runnable方式实现的线程,实际是开辟一个线程,将任务传递进去,由此线程执行。可以实例化多个 Thread对象,将同一任务传递进去,也就是一个任务可以启动多个线程来执行它。这些线程执行的是同一个任务,所以他们的资源是共享。

Calleble接口

1.最大的特点就是可以通过FutureTask获得线程核心处理方法的返回值(run方法是无返回值的
2.get方法会阻塞主线程来等待任务完成。FutureTask非常适合用于耗时的计算,主线程可以在完成自己的任务后,再去获取结果
3. FutureTask被多次调用,依然只会执行一次Runnable任务

JAVA中的多线程之Thread,Runnable和Callable<V> JAVA中线程的实现 线程的实现主要通过三种方式 1. 通过继承Thread类 一个类只要继承了Thread类,那么这个类就可以称之为多线程类,在Thread的子类中必须明确的覆写Thread类的run()方法,此方法称之为线程主体。 但是要启动线程并不能直接调用run()方法,而是要调用从Thread类中继承来的start()方法来启动线程。 在使用了线程后,哪一个线程对象先抢到了CPU资源,哪... 阅读详情

相关推荐

STM32实战:ADXL345传感器驱动与数据采集全解析(IIC/SPI双模式适配)

本文详细解析了STM32驱动ADXL345传感器的全流程,包括IIC和SPI双模式适配、硬件连接、寄存器配置及数据采集处理。通过实战代码示例和常见问题排查指南,帮助开发者快速实现高精度加速度数据采集,适用于运动检测、姿态识别等多种嵌入式应用场景。

weixin_29171087的博客 313

使用Runnable和Callable接口实现多线程的区别

从源码出发分析使用Runnable和Callable接口实现多线程的区别

weixin_43301424的博客 334

FPGA 学习系列(2):Verilog 语法基础

Verilog 由门级建模数据流建模行为建模门级建模(Gate Level Modeling):使用基本逻辑门描述电路,接近硬件物理结构。数据流建模(Data Flow Modeling):使用assign语句进行组合逻辑建模,类似数学方程式。行为建模(Behavioral Modeling):使用always代码块和if-elsecase等控制语句建模,抽象程度较高。Verilog 代码一般由模块(module)组成,每个模块描述一个独立的硬件功能。

Azperk的博客 988

Callable,多线程,Thread

import java.util.concurrent.Callable;   import java.util.concurrent.ExecutorService;   import java.util.concurrent.Executors;   import java.util.concurrent.Future;     /** *//**   * Callab

幸福小猪的专栏 494

STM32 ADC精准采集12V电池电压:从分压电路到软件校准全解析

本文详细解析了STM32 ADC精准采集12V电池电压的全过程,涵盖分压电路设计、电阻选型、ADC配置优化及软件校准方法。针对电池电压监测中的噪声、温漂等挑战,提供了硬件滤波与软件过采样等实战技巧,确保测量精度达到1%以内,满足嵌入式设备对电源管理的严苛要求。

tech5的博客 1014

定制PYNQ的overlay

一、用HLS生成一个定制IP(加速器)(1)首先打开vivado hls,本人的版本是2017.2,点击创建一个新工程。(2)设置工程名和路径,顶层函数设置为add,创建一个新的C++程序,名字叫做adder.cpp,不用在testbench中添加文件。选择板子的时候搜索xc7z020clg400-1,这是PYNQ的板子号,选择完成。             (3)在左侧的菜单栏里选择Sourc...

bramblewalls的博客 1万+

java 线程Thread 技术--1.5 Future与Callable

Callable: 从官方文档说起: 通过实现callable 的called 方法可以使一个任务可以返回一个结果以及可能抛出一个异常; callable 与runnable 是相似的,可以被其他线程潜在的执行,但是runnable不会返回结果总是viod 以及不会抛出检测异常; /** * A task that returns a result and may throw ...

weixin_30765505的博客 152

如何把DeepSeek这个奈斯工具接入到Pycharm里

DeepSeek接入到Pycharm中,提高编程效率,以及帮助解决遇到的问题。

学无止境,何以言满 2623

备战2022,Android中高级面试必知必会

在过去不久的金九银十,有些小伙伴已经找到了理想的工作,当然也有很多小伙伴因为准备不充分,面试挂了,临近年关,最近有很多网友都在求大厂面试题。正好我在9月份和10月份整理和收集了 Android 中高级面试真题解析,于是就发上来分享给大家。 这些题目是网友去字节跳动、小米、oppo、美团、阿里巴巴、腾讯、360、华为、京东等一线互联网公司面试被问到的题目。熟悉本文中列出的知识点会大大增加通过前两轮技术面试的几率。 参考解析:字节跳动技术团队、郭霖、鸿洋、玉刚、掘金博主 xiangzhihong、Focusi

qq_44102588的博客 2862

深入浅出:CosineLRScheduler 调度器的原理与实战应用

本文深入解析了CosineLRScheduler调度器的核心原理与实战应用,详细介绍了余弦退火算法及其在深度学习模型训练中的优势。通过参数配置建议、PyTorch实现示例和常见问题解决方案,帮助开发者高效应用该调度器提升模型性能,特别适用于计算机视觉和自然语言处理任务。

sss66的博客 859

Agentic AI商业化落地指南:提示工程架构师的7步优化法

Agentic AI(具备自主感知、决策与行动能力的智能体系统)是未来AI商业化的核心方向,其价值在于将大模型的“认知能力”转化为“实际行动”,解决复杂商业场景中的自动化与个性化需求。而提示工程(Prompt Engineering)作为连接人类意图与智能体行为的“翻译器”,直接决定了智能体的可控性、效率与用户体验,是Agentic AI商业化落地的关键支撑。本文结合第一性原理与工程实践,提出提示工程架构师的“7步优化法”,覆盖从“商业目标定义”到“规模化推广”的全流程。通过理论框架推导架构设计拆解。

AI架构全栈开发实战笔记 1万+

java thread callable_java多线程系列(一):Thread、Runnable、Callable实现多线程的区别...

实现多线程java实现多线程的方法有三种,分别是继承thread类,实现runnable接口,实现callable接口(call方法有返回值)/*** 继承Thread*/public class MyThread extends Thread{int a = 0;@Overridepublic void run() {//线程的核心实现synchronized (this){try {sleep...

weixin_39864387的博客 225

R语言绘制森林图

运行上述代码后,将会生成一个标题为"森林图示例"的森林图。通过以上代码示例,你可以根据自己的数据集和需求创建定制的森林图。在实际应用中,你还可以进一步调整图形的样式,添加图例、坐标轴标签等,以使森林图更加美观和易于理解。在数据可视化领域,森林图是一种常用的图形类型,用于展示多个分类变量之间的关系。本文将介绍如何使用R语言创建森林图,并提供相应的源代码示例。森林图通常由垂直的线段表示不同类别的观测值,并且线段的长度表示数值变量的大小。上述代码中,我们为不同的类别分别指定了蓝色和红色作为颜色映射关系。

TechNovaX的博客 1045

java 多线程callable_java多线程系列(一):Thread、Runnable、Callable实现多线程的区别...

实现多线程java实现多线程的方法有三种,分别是继承thread类,实现runnable接口,实现callable接口(call方法有返回值)/*** 继承Thread*/public class MyThread extends Thread{int a = 0;@Overridepublic void run() {//线程的核心实现synchronized (this){try {sleep...

weixin_42131367的博客 138

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

Java中Runnable和Thread以及Callable的区别

在java中,其实java中实现 多线程有三种方法,一种是继承Thread类;第二种是实现Runnable接口;第三种是实现Callable接口。1,继承Thread        Thread类是在java.lang包中定义的。一个类只要继承了Thread类同时覆写了本类中的run()方法就可以实现多线程操作了,但是一个类只能继承一个父类,这是此方法的局限。        下面看例子:packag

huang211630的专栏 6619

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Thread类、Runnable接口、Callable接口实现多线程的区别

环境:JDK14 一、继承Thread类实现多线程 Java中有一个java.lang.Thread的类,只要继承了此类就表示:这个类为线程的主体类,但还需要覆写Thread类中提供的一个run()方法,而这个方法就属于线程的主方法(主方法是不能有返回值),多线程要执行的功能都应该在run()方法中定义。 public class ThreadDemo { public static void main(String[] args) { MyThread threadA = new

Yu_Mariam的博客 800

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

多线程Thread、Runnable 、Callable实现方式

系列文章目录 文章目录系列文章目录前言一、创建线程的常用三种方式1、继承Thread类2、实现Runnable接口(重点)以多个线程并发,解决方法为例3、 实现Callable接口(JDK1.5版本之后引入的)总结 前言 通过继承Thread类或者实现Runnable接口、Callable接口都可以实现多线程,不过实现Runnable 接口与实现Callable接口的方式基本相同,只是Callable接口里定义的方法返回值,可以声明抛出异 常而已。因此将实现Runnable接口和实现Callable接口归

zhx__的博客 4100

Java多线程Thread/Runnable/Callable之间的区别

编写多线程程序一般有三种方法,Thread,Runnable,Callable。 1. Runable Runnable是个接口,使用很简单: 1. 实现该接口并重写run方法2. 利用该类的对象创建线程3. 线程启动时就会自动调用该对象的run方法 package com.callable.runnable; /** * Created on 2016/5/18.

Invoker's Tower 3922

多线程,线程的创建和启动,Thread、Runnable、Callable的用法

大部分时候我们都作者单线程编程,程序都只有一条顺序执行流从main方法开始执行,一次向下执行每行代码。但实际情况是,单线程的程序往往功能非常有限,例如我们要开发一个煎蛋的服务器程序,这个服务器程序需要向不同的客户端提供服务,不同客户端之间互不干扰,这就需要多线程。多线程程序可以包括多个顺序执行流,多个顺序流之间互不干扰。Java提供了非常优秀的多线程支持,程序可以通过非常简单的方式来启动多线程。进程就是一个应用程序(一个进程是一个软件)线程是一个进程中的执行场景/执行单元阿里巴巴进程马云。...

sunzixiao的博客 1390

Thread Runnable Callable Future 的区别

Thread Runnable Callable Future 的区别

qq_41956014的博客 8191

Java中Callable、Runnable和Thread 线程的区别与使用详解

CallableRunnable和Thread都是 Java 多线程编程中的重要概念。通过理解它们的区别和使用方法,可以更好地设计和实现多线程程序。在实际开发中,根据具体需求选择合适的方式,可以提高代码的可读性和可维护性。

C_V_Better的博客 1074

Java 多线程基础:Thread 和 Runnable 到底有何不同?

在Java多线程开发中,Thread和Runnable是两个核心概念,常被初学者混淆。Runnable是一个函数式接口,仅定义了一个run()方法,而Thread是一个类,实现了Runnable接口,并提供了线程的创建和管理功能。从使用方式上看,继承Thread类或实现Runnable接口都可以启动新线程,但推荐使用Runnable,因为它更灵活、可复用,符合组合优于继承的设计原则。Thread通过构造函数接收Runnable实例,并在启动时执行其run()方法,体现了职责分离的设计哲学。实际开发中,应首选

小健学Java的博客 2294

Java多线程的实现(进程与线程的概念、继承Thread类实现多线程、实现Runnable接口实现多线程、继承Thread类与实现Runnable接口的区别、实现Callable接口实现多线程)

文章目录1 进程与线程1.1 进程与线程的概念1.2 进程&amp;amp;amp;amp;amp;amp;amp;线程2 Java多线程实现2.1 继承Thread类实现多线程2.2 实现Runnable接口来实现多线程2.3 继承Thread类与实现Runnable借口的区别 1 进程与线程 1.1 进程与线程的概念 什么是进程?   进程: 操作系统中一个程序的执行周期。(比如我们想要在电脑上登录QQ,从双击qq按钮----&amp;amp;amp;amp;amp;amp;gt;

zhao_miao的博客 1433

Runnable、Thread、Callable的区别

线程实现的方式及区别: Runnable、Thread、Callable 实现 Runnable 接口相比继承 Thread 类有如下优势 1)可以避免由于 Java 的单继承特性而带来的局限 2)增强程序的健壮性,代码能够被多个线程共享,代码与数据是独立的 3)线程池只能放入实现 Runable 或 Callable 类线程,不能直接放入继承 Thread 的类 实现 Runnable 接...

qq_41634872的博客 1153

再次理解java多线程的实现 Thread 和Runnable的区别

Thread和Runnable的区别如果一个类继承Thread,则不适合资源共享。但是如果实现了Runable接口的话,则很容易的实现资源共享。main函数,实例化线程对象也有所不同,extends Thread :t.start();implements Runnable : new Thread(t).start();总结:实现implements Runnable接口比继承 extends ...

qq_33608638的博客 1万+
下一篇: java多线程系列(二):Thread的常用方法讲解(sleep、wait、notify)
Qiu7
博客等级 码龄10年 0粉丝 2原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值