Java多线程:Semaphore

Semaphore的使用详解 Semaphore在初始化时需要指定许可证数,Semaphore#acquire方法会尝试获取一定数量的许可证,若许可证数量不足,则当前线程进入阻塞状态。相应地,获取到了许可证的线程,在执行完毕后,需要调用Semaphore#release方法来归还许可证。 阅读详情

Semaphore为并发包中提供用于控制某资源同时可以被几个线程访问的类

实例代码:

// 允许2个线程同时访问
		final Semaphore semaphore = new Semaphore(2);
		ExecutorService executorService = Executors.newCachedThreadPool();
		for (int i = 0; i < 10; i++) {
			final int index = i; 
			executorService.execute(new Runnable() {
				public void run() {
					try {
						semaphore.acquire();
						// 这里可能是业务代码
						System.out.println("线程:" + Thread.currentThread().getName() + "获得许可:" + index);
						TimeUnit.SECONDS.sleep(1);
						semaphore.release();
						System.out.println("允许TASK个数:" + semaphore.availablePermits());  
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			});
		}
		executorService.shutdown();


构造方法1:

    public Semaphore(int permits) {
        sync = new NonfairSync(permits);
    }

permits 初始许可数,也就是最大访问线程数


构造方法2:

    public Semaphore(int permits, boolean fair) {
        sync = (fair)? new FairSync(permits) : new NonfairSync(permits);
    }
permits 初始许可数,也就是最大访问线程数

fair 当设置为false时,线程获取许可的顺序是无序的,也就是说新线程可能会比等待的老线程会先获得许可;当设置为true时,信号量保证它们调用的顺序(即先进先出;FIFO)


主要方法:

void  acquire()   从信号量获取一个许可,如果无可用许可前 将一直阻塞等待,

void acquire(int permits)  获取指定数目的许可,如果无可用许可前  也将会一直阻塞等待

boolean tryAcquire()   从信号量尝试获取一个许可,如果无可用许可,直接返回false,不会阻塞

boolean tryAcquire(int permits)   尝试获取指定数目的许可,如果无可用许可直接返回false,

boolean tryAcquire(int permits, long timeout, TimeUnit unit)   在指定的时间内尝试从信号量中获取许可,如果在指定的时间内获取成功,返回true,否则返回false

void release()  释放一个许可,别忘了在finally中使用,注意:多次调用该方法,会使信号量的许可数增加,达到动态扩展的效果,如:初始permits 为1, 调用了两次release,最大许可会改变为2

int availablePermits() 获取当前信号量可用的许可


JDK 非公平Semaphore实现:

1.使用一个参数的构造创建Semaphore对象时,会创建一个NonfairSync对象实例,并将state值设为传入的值(permits ),

    public Semaphore(int permits) {
        sync = new NonfairSync(permits);
    }
NonfairSync间接的继承了AbstractQueuedSynchronizer实现
final static class NonfairSync extends Sync {
        private static final long serialVersionUID = -2694183684443567898L;

        NonfairSync(int permits) {
            super(permits);
        }

        protected int tryAcquireShared(int acquires) {
            return nonfairTryAcquireShared(acquires);
        }
    }
    abstract static class Sync extends AbstractQueuedSynchronizer {
        private static final long serialVersionUID = 1192457210091910933L;

        Sync(int permits) {
            setState(permits);
        }
AbstractQueuedSynchronizer 的setState方法

    protected final void setState(int newState) {
        state = newState;
    }


2.调用tryAcquire方法时,实际是调用NonfairSync的nonfairTryAcquireShared方法,nonfairTryAcquireShared在父类Sync中实现,

Semaphore# tryAcquire方法:

    public boolean tryAcquire() {
        return sync.nonfairTryAcquireShared(1) >= 0;
    }

Sync的nonfairTryAcquireShared方法

        final int nonfairTryAcquireShared(int acquires) {
            for (;;) {
                int available = getState();
                int remaining = available - acquires;
                if (remaining < 0 ||
                    compareAndSetState(available, remaining))
                    return remaining;
            }
        }

nonfairTryAcquireShared方法通过获取当前的state,以此state减去需要获取信号量的个数,作为剩余个数,如果结果小于0,返回此剩余的个数;如果结果大于等于0,则基于CAS将state的值设置为剩余个数,当前步骤用到了for循环,所以只有在结果小于0或设置state值成功的情况下才会退出。

如果返回的剩余许可个数大于0,tryAcquire方法则返回true;其余返回false。


AbstractQueuedSynchronizer的compareAndSetState方法,

    protected final boolean compareAndSetState(int expect, int update) {
        // See below for intrinsics setup to support this
        return unsafe.compareAndSwapInt(this, stateOffset, expect, update);
    }

3.release方法,释放一个许可 

    public void release() {
        sync.releaseShared(1);
    }
AbstractQueuedSynchronizer的releaseShared方法,

    public final boolean releaseShared(int arg) {
        if (tryReleaseShared(arg)) {
            doReleaseShared();
            return true;
        }
        return false;
    }
release方法间接的调用了Sync的tryReleaseShared方法,该方法基于Cas 将state的值设置为state+1,一直循环确保CAS操作成功,成功后返回true。

        protected final boolean tryReleaseShared(int releases) {
            for (;;) {
                int p = getState();
                if (compareAndSetState(p, p + releases))
                    return true;
            }
        }

根据上面分析,可以看得出,Semaphore采用了CAS来实现,尽量避免锁的使用,提高了性能。





Flink CDC 实战:5分钟搞定PostgreSQL数据实时同步(附避坑指南) 本文详细介绍了如何使用Flink CDC实现PostgreSQL数据的实时同步,包括环境配置、逻辑复制槽创建、Flink环境搭建及实战验证。通过5分钟快速指南,帮助开发者高效搭建实时数据管道,并提供了常见问题排查和生产环境优化建议。 阅读详情

相关推荐

SARScape实战:集成GACOS数据优化InSAR大气校正全流程

本文详细介绍了如何在SARScape软件中集成GACOS数据,以优化InSAR大气校正的全流程。通过实战步骤,从GACOS数据申请、下载、导入,到在单景干涉图和SBAS-InSAR流程中应用,有效剥离大气相位延迟,显著提升形变监测结果的精度与可靠性,实现从“雾里看花”到“拨云见日”的转变。

weixin_28419039的博客 399

Semaphore的使用之方法tryAcquire()的使用

无参方法tryAcquire()的作用是尝试的获得1个许可,如果获取不到则返回false,该方法通常与if语句结合使用,其具有无阻塞的特点。无阻塞的特点可以使线程不至于在同步处一直持续等待的状态,如果if语句判断不成立则线程会继续走slse语句,程序会继续向下运行。 创建Java项目Semaphore_tryAcquire,MyService.java代码如下: package com.yc.

ApatheCrazyFan的博客 2万+

ArcGIS通过已知坐标点转面(通过excel文件,有工具可批量生成面要素)

通过使用ArcGIS中的工具,将坐标点XY数据转换成可视化的点线面矢量数据,更加方便快捷有效的获取对应信息

qq_41046162的博客 3万+

Java 并发编程学习笔记(3) ----Semaphore-tryAcquire()的使用

tryAcquire()的使用 参数使用 当前时刻 tryAcquire(int permits) Acquires the given number of permits from this semaphore, only if all are available at the time of invocation. 尝试去从这个信号量获取指定数量的在调用时都是...

过河的小卒子的博客 4080

一文搞定3D卷积

在讨论卷积核的时候,是不把channel维加进去的 核 = 一个可以滑动的窗口 窗口内不同位置数据之间的权值共享 3D卷积,卷积核会在3个方向上运动,那么卷积核的运动需要有三个自由度(一小块立方体,在一个大面包块内3个方向上滑动 2D卷积,卷积核只在2个方向上运动,因此只有两个自由度(一小片纸,在一大张纸内2个方向上滑动 1D卷积,卷积核只在1个方向上运动,因此只有一个自由度(一条滑窗,在一大长线上1个方向上滑动 一个卷积核运算一次 得到一个输出值 以上讨论了单个卷积核,接下来考虑多通道,一个卷积核对应一

njuptalex的博客 3万+

海思SD3403/SS928开发(二)环境搭建:从零到一构建高效开发环境的实战指南

本文详细介绍了海思SD3403/SS928开发板环境搭建的全流程,包括Ubuntu系统选择、基础配置、开发环境依赖安装、SDK工具链配置等关键步骤。通过实战经验分享,帮助开发者避免常见问题,快速构建高效开发环境,提升开发效率。

weixin_28717683的博客 284

Semaphore使用acquire和tryAcquire方法案例

【代码】Semaphore使用acquire和tryAcquire方法案例。

xuan__xia的博客 1314

ubuntu通过qemu安装银河麒麟V10_Arm_v8 (kylin_v10_飞腾/鲲鹏版)

一、windows下安装vmware虚拟机 二、ubuntu下载地址 https://mirrors.tuna.tsinghua.edu.cn/ubuntu-releases/20.04/ubuntu-20.04.3-live-server-amd64.iso 三、vmware中新建虚拟机,并使用ubuntu-20.04.3-live-server-amd64.iso作为启用盘 。。。在虚拟机中安装ubuntu(略) 四、配置ssh(如果ssh登录不上时配置) 修改openssh的配置 vi /etc/s

u010533742的博客 8704

Semaphore的tryAcquire(int permits)使用说明

Semaphore的tryAcquire(int permits)方法的使用 答: Semaphore对象的有参方法tryAcquire(int permits)的作用:http://www.yayihouse.com/yayishuwu/chapter/1396

qq_30908729的博客 1088

UG\NX二次开发 找不到指定的dlx文件(Specified Dlx file not found)

有群友问:用Ctrl+U运行的时候就报错,找不到指定的dlx文件Specified Dlx file not found。怎么处理。

王牌飞行员_里海的博客 1130

论文阅读:ICLR 2023 FINE-TUNING ALIGNED LANGUAGE MODELS COMPROMISES SAFETY, EVEN WHEN USERS DO NOT INTEND

对大型语言模型(LLMs)进行微调以适应特定用例通常涉及对预训练的LLMs进行进一步的定制。Meta公开发布Llama模型和OpenAI的API允许在自定义数据集上微调GPT-3.5 Turbo,也鼓励这种做法。但是,这种自定义微调与安全成本有何关联?我们注意到,尽管现有的安全对齐基础设施可以在推理时限制LLMs的有害行为,但它们并未涵盖将微调权限扩展到最终用户时的安全风险。我们的红队研究发现,即使是只有几个设计有敌意的训练示例进行微调,也可以破坏LLMs的安全对齐。

CSPhD-winston的博客 811

Java多线程:多线程下的其他组件之CountDownLatch、Semaphore、Exchanger

如果CountDownLatch初始化的count值为1,那么这就退化为一个单一事件了,即是由一个线程来通知其他线程,效果等同于对象的wait和notifyAll,count值大于1是常用的方式,目的是为了让多个线程到达各自的预期状态,变为一个事件进行通知,线程则继续自己的行为。这相当于是一种进化版本的等待/通知机制,它可以的实现的是多个工作线程完成任务后通知多个等待线程开始工作,之前的都是一个工作线程完成任务通知一个等待线程或者一个工作线程完成任务通知所有等待线程。

qq_38470315的博客 430

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

Java多线程:CountDownLatch、CyclicBarrier 和 Semaphore

场景描述:   多线程设计过程中,经常会遇到需要等待其它线程结束以后再做其他事情的情况。 有几种方案:   1.在主线程中设置一自定义全局计数标志,在工作线程完成时,计数减1。主线程侦测该标志是否为0,一旦为0,表示所有工作线程已经完成。   2.使用Java标准的类CountDownLatch来完成这项工作,原理是一样的,计数。 CountDownLatch 一个同...

weixin_30722589的博客 131

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

Java多线程: Semaphore的使用

一. 概念 书上将Semaphore描述成"允许n个任务同时访问同一个资源",我个人觉得这个表述并不准确。Semaphore更像是一个限流装置,管理着有限数量的资源(这一步需要我们自行通过代码完成),每个资源都配有使用许可证,当外部(某线程驱动的任务)需要使用资源时,首先需要向Semaphore申请许可证,接着Semaphore会查看当前许可证的使用情况,若存在尚未被使用的许可证,则...

爱喝咖啡的程序员的博客 326

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

Java多线程:Semaphore信号量

 Semaphore简介         Semaphore是一个计数信号量,它的本质是一个"共享锁"。 信号量维护了一个信号量许可集。线程可以通过调用acquire()来获取信号量的许可;当信号量中有可用的许可时,线程能获取该许可;否则线程必须等待,直到有可用的许可为止。 线程可以通过release()来释放它所持有的信号量许可。       Semaphore为并发包中提供用于

God is Coder 324

java多线程--信号量:Semaphore

信号量:Semaphore信号量为多线程协作提供了更为强大的控制方法。也可以说,信号量是对锁的扩展。无论是内部锁 synchronized 还是重入锁 ReentrantLock,一次都只允许一个线程访问一个资源,而信号量却可以指定多个线程,同时访问某一个资源。常用方法介绍:// 尝试获得一个准入的许可。若无法获得,则线程会等待,直到有线程释放一个许可或者当前线程被中断。public void a...

不一样的烟火 325

Java多线程20:多线程下的其他组件之CountDownLatch、Semaphore、Exchanger

前言 在多线程环境下,JDK给开发者提供了许多的组件供用户使用(主要在java.util.concurrent下),使得用户不需要再去关心在具体 场景下要如何写出同时兼顾线程安全性与高效率的代码。之前讲过的线程池、BlockingQueue都是在java.util.concurrent下的 组件,Timer虽然不在java.util.concurrent下,但也算是。后两篇文章将以...

aocanxie0661的博客 84

Java多线程并发:CyclicBarrier、CountDownLatch、Semaphore 的用法

关注微信公众号:「树森笔记」 1、CountDownLatch(线程计数器 ) CountDownLatch类位于java.util.concurrent包下,利用它可以实现类似计数器的功能。比如有一个任务A,它要等待其他4个任务执行完毕之后才能执行,此时就可以利用CountDownLatch来实现这种功能了。 final CountDownLatch latch = new CountDow...

河湾 362

JAVA多线程基础:Semaphore信号量

介绍 如果我们希望能够控制多个线程可以同时访问一个资源的数量,那么就可以使用Semaphore信号量 业务场景 这个是JDK中的对信号量的例子,这个例子实现了一个对象池,对象池的最大容量为100.因此,当访问请求超过100,未获得资源的线程就会等待,如果有对象返回对象池,等待的线程就可被唤醒 代码如下 class Pool { private static final int MAX_AVAILABLE = 100; private final Semaphore available = ne

yuanyuneixin1的专栏 184

Java多线程: Semaphore

一.CountDownLatch用法  CountDownLatch类位于java.util.concurrent包下,利用它可以实现类似计数器的功能。比如有一个任务A,它要等待其他4个任务执行完毕之后才能执行,此时就可以利用CountDownLatch来实现这种功能了。  CountDownLatch类只提供了一个构造器:1publicCountDownLatch(intcount) { ...

zhuchunyan_aijia的博客 210

Java多线程同步工具类:Semaphore原理剖析

Java多线程同步工具类:Semaphore原理剖析

大数据开发、JAVA开发、人工智能AI 902

Java多线程(十六):多线程下的其他组件之CountDownLatch、Semaphore、Exchanger

前言 在多线程环境下,JDK给开发者提供了许多的组件供用户使用(主要在java.util.concurrent下),使得用户不需要再去关心在具体场景下要如何写出同时兼顾线程安全性与高效率的代码。之前讲过的线程池、BlockingQueue都是在java.util.concurrent下的组件,Timer虽然不在java.util.concurrent下,但也算是。后两篇文章将以例子的形式简单讲解...

scofen的博客 238
上一篇: Java多线程:Executors
胸口碎大石_
博客等级 码龄17年 1154粉丝 82原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值