MySQL数据库:java五子棋课程设计报告摘要

线程是否要锁住同步资源

  • 锁住 悲观锁
  • 不锁住 乐观锁

锁住同步资源失败 线程是否要阻塞

  • 阻塞
  • 不阻塞自旋锁,适应性自旋锁

多个线程竞争同步资源的流程细节有没有区别

  • 不锁住资源,多个线程只有一个能修改资源成功,其它线程会重试无锁
  • 同一个线程执行同步资源时自动获取资源偏向锁
  • 多个线程竞争同步资源时,没有获取资源的线程自旋等待锁释放 轻量级锁
  • 多个线程竞争同步资源时,没有获取资源的线程阻塞等待唤醒 重量级锁

4.多个线程竞争锁时是否要排队

  • 排队公平锁
  • 先尝试插队,插队失败在排队非公平锁

一个线程的多个流程能不能获取同一把锁

  • 能 可重入锁
  • 不能非可重入锁

多个线程能不能共享一把锁

  • 能 共享
  • 不能排他锁

悲观锁与乐观锁

悲观锁与乐观锁时一种广义的概念,体现的是看待线程同步的不同角度。

悲观锁

悲观锁认为自己在使用数据的时候一定有别的线程来修改数据,在获取数据的时候会先加锁,确保数据不会被别的线程修改。 锁实现:synchronized 接口Lock的实现类 适用场景:写操作多,先加锁可以保证写操作时数据正确。

乐观锁

乐观锁认为自己在使用数据时不会有别的线程修改数据,所以不会添加锁,只是在更新数据的时候去判断之前有没有别的线程更新了这个数据。 锁实现:CAS算法,例如AtomicInteger类的原子自增时通过CAS自旋实现。 适用场景:读操作较多,不加锁的特点能够使其读操作的性能大幅度提升。 乐观锁的执行流程: 线程A获取到数据以后直接操作,操作完数据以后准备更新同步资源,更新之前会先判断内存中同步资源是否被更新: 1.如果没有被更新,更新内存中同步资源的值。 2.如果同步资源被其他线程更新,根据实现方法执行不同的操做(报错or重试)。

CAS算法

全名:Compare And Swap(比较并交换) 无锁算法:基于硬件原语实现,在不使用锁(没有线程被阻塞)的情况下实现多线程之间的变量同步。 jdk中的实现:java.util.concurrent包中的原子类就是通过CAS来实现了乐观锁。 算法涉及到的三个操作数:

需要读写的内存值V
进行比较的值A
要写入的新值的B


CAS存在的问题

1.ABA问题 线程1准备用CAS将变量的值由A替换为B,在此之前,线程2将变量的值由A替换为C,又由C替换为A,然后线程1执行CAS时发现变量的值仍然为A,所以CAS成功。但实际上这时的现场已经和最初不同了,尽管CAS成功,但可能存在潜藏的问题。 举例:一个小偷,把别人家的钱偷了之后又还了回来,还是原来的钱吗,你老婆出轨之后又回来,还是原来的老婆吗?ABA问题也一样,如果不好好解决就会带来大量的问题。最常见的就是资金问题,也就是别人如果挪用了你的钱,在你发现之前又还了回来。但是别人却已经触犯了法律。 但是jdk已经解决了这个问题。 想追下源码来着,但是一追发现直接到c了。

2.循环时间长开销大 3.只能保证一个共享变量的原子操作

独家面经总结,超级精彩

本人面试腾讯,阿里,百度等企业总结下来的面试经历,都是真实的,分享给大家!

image

image

image

image

Java面试准备

准确的说这里又分为两部分:

  1. Java刷题
  2. 算法刷题

Java刷题:此份文档详细记录了千道面试题与详解;

image

image

[外链图片转存中…(img-1Mpcxa00-1625415948892)]

[外链图片转存中…(img-UNeNExoK-1625415948893)]

以上所有文档已经打包好,只需要动动手指点击【转发+关注】,然后点击即可免费获取

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Paperback: 1224 pages Data: September 8, 2008 Description: The unexpected pleasure of reading books about databases is that they are often written by authors with highly organized minds. Paul DuBois and his editors at New Riders have assembled MySQL with a clarity and lucidity that inspires confidence in the subject matter: a (nearly) freely redistributable SQL-interpreting database client/server primarily geared for Unix systems but maintained for Windows platforms as well. What isn't "free" about MySQL (the application) is its server's commercial use; all clients and noncommercial server use are free. DuBois's tome isn't free either, but its list price is modest in light of its value and the value of its namesake. The volume is superbly organized into 12 chapters and 10 appendices and contains a concise table of contents and a comprehensive 50-page index. It is peppered with references to the online HTML documentation that comes with the source and binary distributions (which are available and easy to install in stable rpm and tar releases.) The first third of MySQL is an excellent instruction tool for database newbies; the second third is a detailed reference for MySQL developers; and the last third consists of clearly annotated appendices, including C, Perl (but not Python), and PHP interfaces. Perhaps as an indication of the collective will of the developers of MySQL, DuBois does not separate Windows 95/98/NT design or development specifics from its main discussions. Platform-independent design is a goal, not a reality, and users will have to rely on newsgroups and mailing lists for details. Moreover, security issues are addressed in a mere 18 pages, a large part of which is devoted to standard Unix file and network-access permissions. Next to nothing is mentioned about defense against common hacking strategies, the use of secure shell interfaces, or access encryption. Although it is nearly 800 pages in length, DuBois's book is thankfully not encyclopedic. It is a valuable précis of the MySQL database, and its easy-to-skim look and feel will make it an excellent browse for database experts who want to know what is and is not possible within MySQL, the application.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值