java同步线程(一)

【硬刚Java并发】JAVA多线程(五):线程同步(一)线程的同步 本文是对《【硬刚大数据之学习路线篇】从零到大数据专家的学习指南(全面升级版)》的Java并发部分补充。 1问题的提出 多个线程执行的不确定性引起执行结果的不稳定 多个线程对账本的共享,会造成操作的不完整性,会破坏数据。 2模拟火车站售票程序,开启三个窗口售票 1. 多线程出现了安全问题 2. 问题的原因: 当多条语句在操作同一个线程共享数据时,一个线程对多条语句只执行了一部分,还没有执行完,另一个线程参与进来执行。导致共享数据的错误。 3. 解决办法: ... 阅读详情

java同步线程(一)

           同步代码块

线程安全问题,有一个经典的问题:

银行取钱问题:
1、账户类

public class Account {
    //封装账户编号,账户余额两个Eield
    private String accountNo;
    private double balance;
    public Account(String accountNo,double balance)
    {
        this.accountNo=accountNo;
        this.balance=balance;
    }
    //创建的getter和setter方法

    public String getAccountNo() {
        return accountNo;
    }

    public void setAccountNo(String accountNo) {
        this.accountNo = accountNo;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    @Override
    public int hashCode() {
        return accountNo.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (this==obj)
            return true;
        if (obj !=null&&obj.getClass()==Account.class)
        {
            Account target=(Account)obj;
            return target.getAccountNo().equals(accountNo);
        }
        return false;
    }

}

2、取钱的线程类:

public class DrawThread extends Thread{
    private Account account;
    private double drawAmount;

    public DrawThread(String name,Account account,double drawAmount) {
        super(name);
        this.account=account;
        this.drawAmount=drawAmount;
    }
    //当多个线程修改同一个共享数据时,将涉及数据安全性问题

    @Override
    public void run() {
        
            if (account.getBalance()>=drawAmount)
            {
                //突出钞票
                System.out.println(getName()+"取钱成功!吐出钞票:"+drawAmount);
                try {
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                account.setBalance(account.getBalance()-drawAmount);
                System.out.println("\t余额为:"+account.getBalance());

            }
            else {
                System.out.println(getName()+"取钱失败!余额不足!");
            }
        

    }
}

3、Test

public class DrawTest {
    public static void main(String[] args) {
        //创建一个账户
        Account acct=new Account("123456",1000);
        //simulation two thread draw money from one account
        new DrawThread("甲",acct,800).start();
        new DrawThread("乙",acct,800).start();
    }
}

运行结果:

在这里插入图片描述

之所以会出现如图所示的结果,就是因为run()方法的方法体不具有同步安全性-程序中有两个并发线程
在修改Account对象;在第一次输出后做切换后做线程切换,切换给另一个修改Account对象的线程,所以就出现了问题。

为了解决这个问题,java的多线程支持引入了同步监视器解决这个问题,使用同步监视器的通用方法就是同步代码块。

在执行同步代码块之前,必须取得对同步监视器的锁定。

虽然java程序允许使用任何对象作为同步监视器,但想一下同步监视器的目的:阻止两个线程对同一个共享
资源进行并发访问,因此通常推荐使用可能被并发访问的共享资源充当同步监视器。对于上面的模拟取钱程序,我们应该考虑
使用账户(account)作为同步监视器。我们把程序修改成如下形式。

public class DrawThread extends Thread{
    private Account account;
    private double drawAmount;

    public DrawThread(String name,Account account,double drawAmount) {
        super(name);
        this.account=account;
        this.drawAmount=drawAmount;
    }
    //当多个线程修改同一个共享数据时,将涉及数据安全性问题

    @Override
    public void run() {
        synchronized (account){
            if (account.getBalance()>=drawAmount)
            {
                //突出钞票
                System.out.println(getName()+"取钱成功!吐出钞票:"+drawAmount);
                try {
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                account.setBalance(account.getBalance()-drawAmount);
                System.out.println("\t余额为:"+account.getBalance());

            }
            else {
                System.out.println(getName()+"取钱失败!余额不足!");
            }
        }

    }
}

这样就不会出错了

360加固DEX解密与ELF修复技术解析 本文深入解析360加固的DEX解密与ELF修复技术,详细介绍了其多层保护机制、Java层入口分析、Native层加载流程及反调试绕过技巧。通过RC4和zlib解密技术,结合Frida工具实现内存Dump和ELF文件修复,为逆向工程师提供实用解决方案。 阅读详情

相关推荐

Upload Symbols Failed:The archive did not include a dSYM for the LiveKitWebRTC.framework with the UU

你需要从源码构建 LiveKitWebRTC,而不是使用 CocoaPods 安装的预编译 .xcframework。Step 2: 修改 Podfile 使用本地路径引用(不是从源下载的 xcframework)方法 :强制从源码构建 LiveKitWebRTC.framework(推荐)这样它就会编译 WebRTC 并带上正确 UUID 的 dSYM。替换路径为你 clone 下来的 LiveKit 源码位置。Step 1: 克隆源码仓库。

baidu_40537062的博客 2135

Java并发编程的艺术之九----线程池

第一:降低资源消耗。通过重复利用已创建的线程降低线程创建和销毁造成的消耗。 第二:提高响应速度。当任务到达时,任务可以不需要等到线程创建就能立即执行。 第三:提高线程的可管理性。线程是稀缺资源,如果无限制地创建,不仅会消耗系统资源, 还会降低系统的稳定性,使用线程池可以进行统一分配、调优和监控。但是,要做到合理利用线程池,必须对其实现原理了如指掌。 1.线程池的实现原理 从图中可以看...

huangwei18351的博客 467

【FPGA】定点数运算中的位宽优化与截取策略

本文深入探讨了FPGA定点数运算中的核心挑战——数据位宽优化与截取策略。针对定点数在加法、乘法等运算中位宽膨胀的问题,文章详细分析了位宽变化规律,并对比了直接截断、四舍五入和收敛舍入三大截取策略的优缺点及硬件实现方法。通过实战指南与避坑经验,旨在帮助开发者在保证计算精度的同时,高效利用FPGA资源,实现性能与面积的平衡。

weixin_29181861的博客 116

java线程同步(一)

java线程同步 一、使用线程进行数据传递 回调函数进行数据传递 这里举个例子,新建一个ThreadTest07.java代码: import java.util.Random; class data{ public int value = 0; } class work{ public void progress(data data,int n1, int n2, int n3){ { int sum = 0; sum .

hequnwang10的博客 358

避坑指南:STM32定时器测PWM频率占空比时,那些CubeMX没告诉你的细节(蓝桥杯真题衍生)

本文深入解析STM32定时器测量PWM频率和占空比时的关键细节,揭示CubeMX配置中未明确的时钟树原理和输入捕获机制。针对蓝桥杯嵌入式赛题中的常见问题,提供动态调整预分频器、多采样数字滤波等实战解决方案,帮助开发者避免测量误差,提升PWM测量精度和稳定性。

weixin_28692153的博客 339

数据中心GPU芯片性能参数速查表(Nvidia+国产算力卡)

本文提供了一份数据中心GPU芯片性能参数速查表,涵盖Nvidia与国产算力卡两大阵营。文章详细解读了算力、显存、互连技术及功耗等关键性能指标,并对比了A100、H100、昇腾910B等主流型号,旨在帮助用户根据AI训练、推理等实际场景,做出高效的硬件选型与成本评估决策。

a0b1c2d3的专栏 835

JAVA多线程(一):线程创建及线程同步

(1)方式一:继承Thread类(2)方式二:实现Runnable接口(3)方式三:实现Callable接口。

ljz1408的博客 1142

算法基础之数组双指针(Leetcode题型归纳)

数组双指针(Leetcode题型归纳)1.前言2.双指针基础3.相向双指针3.1定义3.2真题分析3.2.1两数之和(1)3.2.2两数之和-输入有序数组(167)3.2.3三数之和(15)3.2.4最接近的三数之和(16)3.2.5四数之和(18)3.2.6盛最多水的容器(11)3.2.7有效三角形的个数(611)4.同向双指针-快慢指针4.1定义4.2真题分析4.1.1删除排序数组中的重复项(26)4.1.2移除元素(27)4.1.3删除排序数组中的重复项(80)4.1.4移动零(283)4.1.5数组

Buluchacha的博客 1034

java线程互斥&同步(一)

Java线程互斥和同步一直是一个较难理解透彻的东西,要弄清楚其本真,还是要先从概念入手: 1、线程之间通过对资源的竞争,包括共享的数据和硬件资源,所产生的相互制约关系,这类线程间的主要问题是互斥和死锁问题,这类关系被称为互斥关系。2、线程之间的相互协同合作,彼此之间直接知道对方的存在,并了解对方的名字,这类进程常常需要通过“进程间通信”方法来协同工作,这类关系被称为同步关系。   概念读...

chaijuntao的博客 516

微带功分器设计与ADS-EM联合仿真实战解析

本文详细解析了微带功分器设计与ADS-EM联合仿真的实战技巧,涵盖特性阻抗计算、ADS原理图设计、版图生成与EM仿真等关键步骤。通过实际案例分享,帮助工程师掌握射频电路设计中的核心技术和调试方法,提升功分器设计效率与性能。

weixin_29280219的博客 450

【研发日记】Matlab/Simulink自动生成代码(二)——五种选择结构实现方法

相比C文本类编程语言,Simulink图形化编程语言的优势是逻辑思路和数据流清晰了很多,劣势是程序执行的时序不明确,而且各个模块的配置使编程的灵活度下降了不少,在使用习惯上面总感觉有各种限制。本文就是拆解Simulink中最基础的几个编程模块,发扬它的优势,避开劣势。

Mr.Cssust的博客 3849

java多线程编程(一)

java多线程编程(一) 基本实现方式及同步原理 三种实现方式: 1、继承Thread Thraad 实现 Runable 源码中的表现: public Thread(Runnable target) { init(null, target, "Thread-" + nextThreadNum(), 0); } 2、实现Runable 这是Runable的...

RoundYuan 1769

概率质量函数(PMF)、概率密度函数(PDF)、累积分布函数(CDF)

1.概率分布函数(Probability Distribution Functions) 笔记来源:Probability Distribution Functions (PMF, PDF, CDF) 1.1 离散型:PMF和CDF 1.2 连续型:PDF和CDF 累积分布函数的导数 === 概率密度函数的函数值 dF(x)dx=f(x) \frac{dF(x)}{dx}=f(x) dxdF(x)​=f(x) 概率密度函数与 xxx 轴围成的面积 === 累积分布函数的函数值 ∫−∞xf(x)d

一个搬运知识的笨小孩 3万+

【JVM调错】由于GC导致生产环境高CPU错误

在2020年3月时候突然接到用户反映产品很卡。 作为一个开发兼运维(临时接管)的好处就凸显出来了,上来就干。 首先查看内存和CPU 发现CPU问题: 在这里插入图片描述 2.拉取 25376 的 stack 信息【保存状态】 3、通过 top -Hp 命令 发现有如下线程占用较高cpu 4、根据线程占用率榜对应 栈信息发现: 1)占用39.2%以上的线程号为 25378~25391(转换为16...

RoundYuan 610

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

SSO 与 CAS

一、什么是单点登录? 从以下几点谈起: 1、为什么产生单点登录? 在现在每个企业都有不同的产品,豆瓣读书、豆瓣电、豆瓣。。。影甚至同一个产品他的域名都是不同的,比如 这些情况如果每次都登陆一次就会产生不便对于用户。 2、什么是单点登录? 举一个经典例子: 非单点登录:我去迪斯尼去玩,玩一个项目就得买一张票。单点登录就是我买了一张通票去哪玩都是这张票。 3、单点登录原理: 推荐一篇帖子,讲的很好...

RoundYuan 580

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

HashMap和Hashtable的区别

HashMap: public class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Cloneable, Serializable { Hashtable public class Hashtable<K,V> extends Dictionary<...

RoundYuan 436

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

HashCode和equals的区别(二)

HashCode和equals的区别: String方法的equals方法和HashCode方法 String的HashCode方法 /** Cache the hash code for the string */ private int hash; // Default to 0 /** The value is used for character storage. */ ...

RoundYuan 434

java多线程编程(四)

java多线程编程(四) Java内存模型 引言: 内存模型的基础----内存模型相关的基本概念 java内存模型中的顺序一致性–重排序与顺序一致性内存模型 同步原语(synchronized、volatile和final)的内存语义及重排序规则在处理器中的实现 java内存模型的设计,主要介绍java内存模型的设计原理,及其与处理器内存模型和顺序一致性内存模型的关系 Java内存模...

RoundYuan 396

线程池的创建

线程池的创建 java 通过 Executors提供四种线程池,分别为: newCachedThreadPool创建一个可缓存线程池,如果线程池长度超过处理需要,可灵活回收空闲线程,若无可回收,则新建线程。 newFixedThreadPool 创建一个定长线程池,可控制线程最大并发数,超出的线程会在队列中等待。 newScheduledThreadPool 创建一个定长线程池,支持定时及周期性...

RoundYuan 375

解读StringBuffer、StringBuilder、String区别

源码级StringBuffer和StringBuilder以及String区别 作为一个面试常问的问题: 首先看一下源码: public final class StringBuffer extends AbstractStringBuilder implements java.io.Serializable, CharSequence public final class ...

RoundYuan 352

JDK 源码下载 快速

JDK 源码下载 快速 搜索JDK 源码下载,一般大家看到的都是从 这里 http://hg.openjdk.java.net/ 下载,我尝试之后发现下载巨慢,而且还一直中断。那么有没有快速的下载方法呢? 有的。 github 官方jdk 仓库: https://github.com/openjdk/jdk 官方打包好的 http://jdk7.java.net/source.html...

RoundYuan 338

java线程池 实现原理

java线程池 实现原理 线程池的好处: 降低资源消耗 提高响应速度 提高线程的可管理性 线程池的实现原理 下图是提交一个新任务到线程时,线程池的处理流程 ! ThreadPoolExecutor执行execute方法分下面4种情况 如果当前运行的线程少于corePoolSize,则创建新线程来执行任务(注意!执行该步骤需要获取全局锁) 如果运行的线程等于或者多于corePoolSize ,...

RoundYuan 334

java控制线程(二)

java控制线程(二) 控制线程-守护线程 后台线程: what: 有一种线程,它是在后台运行的,它的任务是为其他的线程提供服务,这种线程被称为“后台线程(Daemon Thread)” 又称为"守护线程“或”精灵线程“。 JVM的垃圾回收机制就是典型的后台线程。 特征: 如果所有的前台线程都死亡,后台线程会自动死亡。 How: 调用Thread对象的setDaemon...

RoundYuan 320

HashCode和Equals的区别

我们首先来看一下HashCode的源码: /** * Returns a hash code value for the object. This method is * supported for the benefit of hash tables such as those provided by * {@link java.util.HashMap}...

RoundYuan 319

JVM讲解-1

JVM JVM详解 在最近学习了一下JVM的知识,现在将学到的做一个总结 overview 一、什么是JVM? 1、jvm的定义 2、jvm的位置 3、jvm的意义 二、JVM的构造 1、类加载子系统与方法区 2、方法区 3、java堆 4、程序计数器 5、java栈 6、本地方法栈 7、直接内存 ...

RoundYuan 293

java同步线程(二)

java同步线程(二) 同步方法 同步方法: 使用synchronized关键字来修饰某个方法,则该方法称为同步方法。 同步方法的同步监视器是this,也就是该对象本身。 通过同步方法可以非常方便地实现线程安全的类,线程安全的类具有如下特征。 1、该类的对象可以被多个线程安全地访问。 2、每个线程调用该对象的任意方法之后都将得到正确结果。 3、每个线程调用该对象的任意方法...

RoundYuan 277
上一篇: java控制线程(三)
下一篇: java同步线程(二)
Round_Yuan
博客等级 码龄10年 26粉丝 78原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值