JAVA多线程实现-实现Callable接口

并发编程之Callable方法的详细解析(带小案例) 原生Thread多次执行start会抛出IllegalThreadStateException非法的线程状态异常,Callable也是。使用callable就相当于另外开了一条线程运行,调用get方法就相当于要获取这条线程的运行结果。运行结果:(可以看到 只执行了一次come in的输出,即call()这个方法的代码只运行了一次)callable多次运行,只会计算一次结果。Callable与Runnable的区别。(第三种线程实现方式) 阅读详情

1. 实现Callable接口

public class ImplementsCallable implements Callable<Integer>

2. 重写接口call()方法,即线程执行内容。

    @Override
    public Integer call() throws Exception {
	Thread.currentThread().setName("Thread in Callable");
	System.out.println(Thread.currentThread().getName() + " i = " + i);
	return null;
    }

3. 通过创建FutureTask来执行给定的Callable

         Callable<Integer> oneCallable = new ImplementsCallable();
	//Creates a FutureTask that will, upon running, execute the given Callable.
	FutureTask<Integer> oneTask = new FutureTask<>(oneCallable);
	//注释:FutureTask<Integer>是一个包装器,它通过接受Callable<Integer>来创建,它同时实现了Future和Runnable接口。

4. 通过new Thread(oneTask)创建线程对象。通过start()方法启动线程。

        //由FutureTask<Integer>创建一个Thread对象:
	Thread oneThread = new Thread(oneTask);
	oneThread.start();

完整代码:

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

public class ImplementsCallable implements Callable<Integer>{
	//尖括号中也可以是其他任意类
	public static int i = 0;

	public static void main(String[] args) {
		Thread.currentThread().setName("Thread main");
		
		Callable<Integer> oneCallable = new ImplementsCallable();
		//Creates a FutureTask that will, upon running, execute the given Callable.
		FutureTask<Integer> oneTask = new FutureTask<>(oneCallable);
		//注释:FutureTask<Integer>是一个包装器,它通过接受Callable<Integer>来创建,它同时实现了Future和Runnable接口。
		
		//由FutureTask<Integer>创建一个Thread对象:
		Thread oneThread = new Thread(oneTask);
		oneThread.start();
		print();
		
		

	}

	@Override
	public Integer call() throws Exception {
		Thread.currentThread().setName("Thread in Callable");
		System.out.println(Thread.currentThread().getName() + " i = " + i);
		return null;
	}
	
	public static void print() {
		i=0;
		for (i = 0; i < 10; i++) {
			System.out.println(Thread.currentThread().getName() + ":" + i);
		}
	}

}




实现线程的方式(继承Thread类,实现Runnable和Callable接口)(小白教程含泪总结,读完必会!!!!) 在Java中使用Thread类表示线程,每一个线程都是Thread类的对象或者子类的对象,相当于Thread类是所有线程的父类,所有的线程对象都是一个任务,需要调度器安排序列被CPU执行,在使用了Thread类时,这些线程对象会被同时执行;在自定义类继承implements Callable接口时,需要注意后必须跟一个泛型类,该泛型类的类型可以自定义,pubic class MyCallable implements Callable<T>不能直接使用Thread类中的方法,没有返回值; 阅读详情

相关推荐

java学习线程篇之多线程的实现方式:继承Thread类、实现Runnable接口或Callable接口~

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

TingtingYang 1339

java 多线程之 implements Callable

线程的实现方式 java 多线程之 extends Thread java 多线程之 implements Runnable java 多线程之 implements Callable 线程池的使用 线程池简介 ThreadPoolExecutor java 线程池之 newScheduledTh......

比嗨皮兔 6137

Java创建多线程的3种方法:继承Thread类、实现Runnable接口、实现Callable接口

线程(Thread)‌是程序的执行单元,一个进程内可包含多个线程。利用多核 CPU 并行执行任务(如并发计算、批量处理)。主线程不阻塞(如 GUI 界面后台加载数据)。共享进程资源(内存、文件句柄),减少上下文切换开销。Java 多线程通过‌并发执行‌提升程序效率,核心实现方式包括:Thread、Runnable 和 Callable,需注意‌线程安全‌问题(同步机制)。实际开发中优先使用‌线程池‌和‌并发工具类‌(如 JUC 包)简化编码并优化性能。

pan_junbiao的博客 807

创建线程的方式:3.实现Callable接口

实现Callable接口 实现Callable接口,需要返回值类型:implements Callable 重写call方法,需要抛出异常 :public Boolean call() throws Exception {} 创建目标对象 :CallableTest callableTest = new CallableTest(); 创建执行服务:ExecutorService service = Executors.newFixedThreadPool(1); 提交执行:Future

我有满天星辰的博客 473

基于FME—三调篇—尖锐角及小缝隙处理

1 问题分析: 该功能实现在FME较为简单,相对ARCGIS模型构建器以及ARCGIS ENGINE,FME更适合无代码基础的人群。在三调内业数据处理要求中,尖锐角是不允许存在的。本文基于FME实现了对尖锐角的自动查询与消除以及自动处理在消除尖锐角过程中产生的缝隙,并进行了拓扑检查,实现自动化批量处理尖锐角的功能,提高工作效率。 2 总体思路: 2.1 实现功能分析: 1.找出小于指定角度的尖锐角...

qq_33315579的博客 9184

毕业论文管理系统的设计与实现

毕业论文工作是高等学校本科培养阶段的一个重要环节。目前论文管理工作存在着许多问题,例如人工管理极为不便;学生对论文所要撰写的内容并不十分了解,与指导老师的沟通非常不便;老师的指导监督也很难完全到位;手工评审的效率低等。而现有的一些毕业论文信息管理或答辩评审系统只是实现了部分网上交流和评审管理的功能,在答辩评审的自测和项目指标权重等方面都存在着一定的不足。因此,本文设计的毕业论文管理系统采用B/S模式开发。其中,Browser层使用JSP技术开发;

wqq_992250277的博客 3185

6.实现 Callable 接口

6.实现 Callable 接口前言本篇章来介绍一下创建线程的第三种方式,其中创建线程一共有四种方式:继承 Thread 类实现 Runnable 接口实现 Callable 接口使用线程...

DevOps海洋的渔夫@专栏 1579

VASPKIT绘制平面平均电荷差分密度

平面平均密度差(planar-averaged electron density difference)是密度差的衍生。密度差是个三维空间函数,经常通过绘制平面图、等值面图方式图形化考察。虽然这两种图很直观,但平面图会受到截面选取的影响,而等值面图会受到等值面数值(isovalue)选取的影响,因此都有一定任意性,也不容易定量讨论。对于电子转移有比较明确方向的情况,可以绘制平面平均密度差曲线,由此可以清楚地考察垂直于选取的方向上每个截面上的密度差积分值,在定量讨论、对比上比较便利。

weixin_43948934的博客 1万+

详述Java实现Callable接口实现多线程的方式

公司项目忙的晕头转向,终于有时间可以看点自己想看的东西了。在这里把最近学习的实现Callable接口实现多线程的方式做一个总结: 首先我们都知道,在Java中最常见的是继承Thread类和实现Runnable接口来实现多线程( 这里我推荐采用实现接口的方式来实现多线程,原因有两点: 1、Java的设计是单继承的设计,如果采用继承Thread的方式实现多线程,则不能继承其他的类。 2、采用接...

weixin_42606135的博客 2万+

RK3588与银河麒麟V10 SP1 2403深度适配:国产化硬件与操作系统的完美融合

本文深入探讨了RK3588处理器与银河麒麟V10 SP1 2403操作系统的深度适配,展示了国产化硬件与操作系统的完美融合。通过性能验证和实际应用测试,证明了这套组合在多媒体处理、AI推理和日常办公中的卓越表现,实现了完全自主可控的计算平台。

weixin_29194255的博客 250

船舶轨迹预测中的5个常见坑:基于LSTM单步预测的避坑实践

本文针对船舶轨迹预测中LSTM单步预测的常见问题,系统总结了五个典型陷阱及避坑实践。重点分析了如何正确处理AIS数据的非均匀采样与清洗、对航向角进行周期性编码、采用轨迹级归一化策略、缓解单步滚动预测的误差累积,并设计贴合业务的评估指标。这些实践能有效提升预测模型的准确性与实用性。

cnn8visionary的博客 634

Java多线程之Callable接口的实现

文章目录有返回值的线程线程池管理测试结果 有返回值的线程 package com.zfinfo; import java.util.List; import java.util.Vector; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.c...

IT打工匠 2609

高效爬取懂车帝车型数据:从静态解析到动态反爬实战

本文详细解析了如何高效爬取懂车帝车型数据,从静态HTML解析到动态接口反爬的完整实战路径。文章重点介绍了使用浏览器开发者工具定位数据、应对CSS混淆与参数加密等反爬策略,并提供了整合静态与动态抓取逻辑的Python代码示例,帮助开发者稳健地获取结构化车型信息。

wind6的博客 937

Java多线程实现之Callable接口深度解析

Runnable接口是我们在Java中实现多线程任务的常用方式,然而Runnable的run()方法没有返回值,这在需要获取线程执行结果的场景下显得力不从心。Java 5引入的Callable接口和Future机制解决了这个问题,允许线程任务返回结果并处理异常

aa_hdkf_vg的博客 1122

042、双管反激的电压应力优势

【摘要】本文通过300W工业电源炸管案例,对比分析了单管与双管反激拓扑的电压应力差异。单管反激因漏感能量难以处理,尖峰电压可达1180V,需依赖RCD吸收电路但效率低下;双管反激通过钳位二极管将漏极电压限制在输入电压水平(实测650V),能量回馈使效率提升2-3%。虽增加两个MOS管,但可选用600V器件(单管需1200V),总成本反降15%以上。作者建议150W以上或高压输入场景优先采用双管反激,其确定的电压应力可显著提升可靠性,避免单管反激的参数玄学问题。关键设计要点包括快恢复二极管选型、紧凑布局及漏感

Jack010169的博客 88

Python + OpenCV 计算视频中运动最慢小球的坐标验证码

本文提出一种基于Python和OpenCV的视频分析方法,用于检测多个运动小球中最慢运动目标的坐标。方法主要包括:1) 通过背景差分和形态学处理提取运动前景;2) 基于轮廓面积和圆形度筛选候选小球;3) 利用图像矩计算小球质心坐标;4) 通过近邻关联构建运动轨迹;5) 根据轨迹平均速度确定最慢目标。该方法能有效处理包含线条干扰和静态大圆干扰的背景,稳定输出最慢小球的中心坐标。实验结果表明,该方法能准确识别运动最慢的小球并定位其位置。

码王吴彦祖的博客 116

Java多线程的三种实现方式(继承Thread ,实现Runnable接口,实现Callable接口)

文章目录1、继承Thread 实现run方法2、 实现Runnable接口3、 Callable接口 JAVA多线程实现方式主要有三种: 继承Thread类、 实现Runnable接口、 使用ExecutorService、Callable、Future实现有返回结果的多线程。其中前两种方式线程执行完后都没有返回值,只有最后一种是带返回值的。 1、继承Thread 实现run方法 public class ThreadDemo1 { public static void main(String[]

m0_47422889的博客 756

计算机控制技术及应用

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

Java 多线程编程:继承 Thread 类、实现 Runnable 接口、实现 Callable 接口

Java 多线程编程:继承 Thread 类、实现 Runnable 接口、实现 Callable 接口

李长渊的博客 1123

深度学习工具包 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")

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

Java 多线程实现方式三:实现 Callable 接口

Java 多线程实现方式三:实现 Callable 接口 java 通过实现Callable 接口来实现多线程相比较于继承Thread 接口和 实现Runnable 接口比较麻烦,但好处是可以有返回值。 基本套路: 1. 创建目标对象 2. 创建执行服务 3. 提交执行 4. 获取结果 5. 关闭服务 6. 继续方式一的下载图片,改写一下: public class CDownload implements Callable<Boolean>...

qq_39827033的博客 1014

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

Java多线程详解七 ( 实现Callable接口 )

之前我们讲解了Java实现多线程的两种方式: 继承Thread类 实现Runnable接口 那么我们今天来看一下如何使用实现Callable接口的方式实现多线程 代码: package wewi; import java.util.concurrent.Callable; import java.util.concurrent.FutureTask; /** * @author LFDMW * @date 2020-11-25 22:23 */ public class CallAbleTes

冷风DMW的博客 360

Java-实现Callable接口创建多线程

Java-实现Callable接口创建多线程 1.实现Callable接口和实现Runnable比较 call方法可以有返回值 call方法可以抛出异常,被外部操作捕获异常 callable支持泛型 2.代码举例 实现Callable接口创建多线程分为6步,第6步根据实际需求来写 package com.lmw.thread3; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; i

ispringmw的博客 2519

java多线程实现方式--Callable接口

java实现多线程的方式有:继承Thread类;实现Runnable接口;实现Callable接口;实现Callable接口,需要FutureTask类的支持,用于接收运算的结果,FutureTask类实现了Future接口和Runnable接口;Callable的任务执行后可以有返回值,并且可以抛出异常;import java.util.concurrent.Callable; import j

xk优快云的博客 586

[Java多线程]使用callable接口实现多线程

目录 call方法: Future接口: RunnableFuture接口: 泛型相关基础知识: https://blog.youkuaiyun.com/weixin_42645168/article/details/102768764 学习callable接口之前先观察collable接口的包: jdk1.5新增的高并发编程包(JUC) package java.util.concurre...

weixin_42645168的博客 516

Java创建多线程(继承Thread类,实现Runnable接口,实现Callable接口,使用线程池)

Java创建多线程 Java语言的JVM允许程序运行多个线程,它通过java.lang.Thread类来体现。 Thread类的特性 每个线程都是通过某个特定Thread对象的run()方法来完成操作的,经常把run()方法的主体称为线程体 通过该Thread对象的start()方法来启动这个线程,而非直接调用run() 创建多线程的四种方式 java中创建多线程的四种方式,分别是继承Thread类,实现Runnable接口,jdk5.0以后又增加了两种方式:实现Callable接口和使用线程池。 继承

qq_41117896的博客 4779

Callable 接口实现java 的多线程

java 中创建多线程最常见的是继承Thread 的子类重写run() 方法,还有就是实现Runnable 接口 我们最好使用实现了Runnable 接口的方法原因有两点: ①因为java 的单继承的特点,所以说使用第一种方法不能继承其他父类了 ②采用接口的方式便于实现数据共享,线程的启动需要Thread类的start方法,如果采用继承的方式每次新建一个线程时,每个新建线程的数据都会单独的存在线程内存中,这样每个线程会单独的操作自己线程的数据,不能更好的实现线程之间的数据共享) 如果我们想要我们的线程有返回

tianynnb的博客 2323
上一篇: JAVA多线程实现-实现Runnable接口
下一篇: JAVA多线程实现-单线程化线程池newSingleThreadExecutor
山禾_Abel
博客等级 码龄15年 30粉丝 34原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值