Java高并发编程实战1,那些年学过的锁

一、进程与线程

程序本身是静态的,是众多代码的组合产物,代码保存在文件中。如果程序要运行,则需要将程序加载到内存中,通过编译器将其编译成计算机能够理解的方式运行。
如果想启动一个Java程序,先要创建一个JVM进程。
进程是操作系统进行资源分配的最小单位,在一个进程中可以创建多个线程。多个线程各自拥有独立的局部变量、线程堆栈和程序计数器,能够访问共享的资源。

  1. 进程是操作系统分配资源的最小单位,线程是CPU调度的最小单位;
  2. 一个进程中可以包含多个线程;
  3. 进程与进程之间是相对独立的,进程中的线程之间并不完全独立,可以共享进程中的堆内存、方法区内存、系统资源等;
  4. 进程上下文的切换要比线程的上下文切换慢很多;
  5. 某个进程发生异常,不会对其它进程造成影响,但,某个线程发生异常,可能会对此进程中的其它线程造成影响;

在这里插入图片描述

二、线程组与线程池

1、线程组

线程组可以管理多个线程,顾名思义,线程组,就是把功能相似的线程放到一个组里,方便管理。

高并发场景加锁方式及存在的问题 在多线程高并发场景下,为了保证共享资源的正确性,通常会采用加锁的方式。关于加锁以及一些相关的问题,这里根据个人学习了解的做个汇总。 阅读详情

相关推荐

深入理解CAS与乐观锁:Java高并发编程实战指南

State next;不可变状态对象保证原子性版本号与值绑定更新提供条件更新接口CAS与乐观锁是现代高并发系统的基石,从Java并发包到分布式数据库,其思想无处不在。随着硬件技术的发展,异步编程模型的普及,理解这些底层机制对构建高性能系统愈发重要。建议读者通过Java并发包的源码(如AQS实现)深入学习,并结合具体业务场景实践创新。如何设计一个支持批量更新的乐观锁系统?需要考虑哪些维度?

wx19930913的博客 498

无锁编程与并发容器实战:Java高并发性能翻倍的核心技巧

*** 自定义无锁栈(基于CAS自旋)* 场景:高并发下的栈操作,性能远超加锁栈*/// 栈顶节点(原子引用)// 节点定义// 无锁入栈// CAS自旋:直到入栈成功do {// 获取当前栈顶// 新节点指向旧栈顶// CAS更新栈顶:如果当前栈顶还是oldTop,就替换为newNode} while (!// 无锁出栈// CAS自旋:直到出栈成功do {if (oldTop == null) { // 栈空// 新栈顶为旧栈顶的下一个节点。

2601_94871597的博客 533

Java高并发编程实践指南:汪文君的实战教程

Java并发编程是构建高性能、可扩展应用程序的关键。在本章中,我们将从基础开始,逐步深入了解Java并发的世界。首先,我们会介绍并发编程的基本概念,如进程、线程与并发、并行的区别。接着,我们会探讨Java中的线程创建与管理,包括实现Runnable接口、继承Thread类以及使用FutureTask等。在此基础上,我们将介绍线程的生命周期和线程池的基本概念。为了帮助读者更好地理解,我们将通过代码示例演示如何创建线程以及如何使用线程池,从而为深入学习后续章节奠定坚实的基础。

weixin_35754962的博客 1148

数字IC设计技能篇之如何在RTL级降低功耗?

以上就是本次降低芯片功耗的部分心得和收获,由于是在芯片设计阶段还没办法后端直接给出power的报告,前端一般使用spyglass和fsdb来进行功耗分析,后续会更新如何使用spyglass在前仿阶段进行power的分析,以及持续更新有关RTL级降低功耗的相关内容。

mzynk的博客 1206

TPAMI 2025新作LRFormer复现笔记:我的Windows 11 + RTX 4090配置全流程

本文详细记录了在Windows 11系统下使用RTX 4090显卡复现TPAMI 2025顶会论文LRTransformer的完整流程,包括硬件配置、系统优化、Python环境搭建及模型训练中的常见问题解决方案。特别针对Windows平台特有的路径管理、CUDA版本冲突和显存优化等关键技术细节提供了实用指南,帮助开发者高效完成环境搭建和模型训练。

weixin_29094301的博客 416

Windows server Database 2025 安装 i225/i226 网卡驱动

Windows server Database 2025 安装 i225/i226 网卡驱动 windows这比坏得很,intel消费级网卡不准在服务器系统上安装。你要说他是异构不支持?他就纯粹恶心人。 之前已经安装过一次,但是今天database预览版一更新,又给我把网卡驱动杀了,气死,写一篇教程。 到这里就完成了,总之还是想辱骂windows,提供便捷的同时又人为制造困难,多少有点(隔壁linux内核直接自带全家桶了就一省心) 并且近年Intel的新U安装显卡驱动和普通声卡驱动都不会出声

低温热源的博客 1万+

ADS 2023 实战:手把手教你仿真一个中心频率 2.4GHz 的带通滤波器(附工程文件)

本文详细介绍了使用ADS 2023软件设计和仿真中心频率2.4GHz带通滤波器的全流程,包括工程准备、指标定义、原理图设计、仿真优化及实际电路实现。通过切比雪夫滤波器拓扑和参数优化,实现高性能的带通滤波器设计,适用于无线通信系统。附有工程文件和常见问题解决方案,助力工程师快速掌握射频滤波器设计技巧。

weixin_30790841的博客 482

【大语言模型 14】Transformer权重初始化策略:从Xavier到GPT的参数初始化演进之路

权重初始化是深度学习训练成功的隐秘基石,特别是在Transformer这样的深层架构中,合适的初始化策略能够决定模型的训练稳定性和收敛速度。本文从经典的Xavier和He初始化出发,深入解析Transformer特有的初始化策略,通过数学推导、代码实现和实验分析,揭示不同初始化方法对大语言模型训练的深层影响。我们将探讨为什么GPT系列模型采用特定的初始化方案,以及如何针对不同层设计最优的初始化策略。

熵数实验室 1690

SecOC专题之新鲜值TripCnt

本系列为一步步拆解新鲜值的分发及管理而撰写文章属于原创,根据自身开发经验及理解撰写,若有错误请指出Trip Counter是新鲜值中变化最慢的一个part,并且自增到最大值时,会从头开始翻转计数。Trip Counter需要收发双方都保存,由于其变化较慢,所以不会经常进行同步该值。这就要求开发过程中保证每次对该值的读写必须要正确。

qq_22969363的博客 1161

使用LSTM进行多任务学习:共享模型预测多个目标

多任务学习是一种机器学习方法,旨在通过同时学习多个相关任务来提高模型的学习效率和泛化能力。MTL的核心思想是共享模型的参数,从而在不同任务之间捕捉到共享的特征。长短期记忆网络(LSTM)是循环神经网络(RNN)的一种改进版本,专门用于解决传统RNN在处理长序列时出现的梯度消失和梯度爆炸问题。LSTM通过引入多个门控机制(输入门、遗忘门和输出门)来控制信息的流动。本文详细探讨了如何使用LSTM进行多任务学习。我们介绍了多任务学习的理论基础、LSTM的特点,以及如何构建和训练一个多任务LSTM模型。

斌擎科技 1157

基于YOLOv10深度学习的花生种子霉变检测系统

YOLO(You Only Look Once)是当前最先进的目标检测算法之一,具有快速、精准的特性。YOLOv10是YOLO系列的最新版本,相较于之前的版本,YOLOv10在特征提取、模型精度和速度上都有了显著的提升。YOLOv10采用了更深的卷积神经网络、更多的跨层特征融合方法,使得其在不同尺寸物体的检测和复杂场景的处理上都表现出了优异的性能。YOLOv10特别适合应用在需要快速处理并检测大量图像的任务中,如花生种子霉变检测等,能够实现精准、高效的检测。

2201_76125393的博客 649

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

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

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

上一篇: Java设计模式10,建造者模式
下一篇: Java 下数据业务逻辑开发技术 JOOQ 和 SPL
哪 吒
哪 吒 2022年度博客之星TOP 1 2022年度博客之星TOP 1 领域专家: 后端开发技术领域 领域专家: 后端开发技术领域
博客等级 码龄9年 59万+粉丝 2962原创
评论 55
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

哪 吒

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值
⌂ 换网址